Quantcast
Channel: User Norbert - Stack Overflow
Viewing all articles
Browse latest Browse all 42

Answer by Norbert for Go maps - pulling records based off key value. A question of search speed and behavior

$
0
0

Your measurement of performance contains other elements:

if v, ok := itenariesMap[i]; ok {        w.WriteHeader(http.StatusOK)        fmt.Fprintf(w, utils.PrettyPrint(s.TravelItenariesCSV[v])) // this takes ~500.0µs        //fmt.Fprintf(w, utils.PrettyPrint(v)) // this takes ~50.0µs    }    defer utils.PrintExecutionTime(startTime)

does 2 things: fmt.Printf takes time. For 1 variable it will be x, it will scale accordingly for 10x the parameters

Second: When measuring throughput, do not use defer: Defer runs later (hence the term defer).

So to measure the map performance you could do:

for _, v := range s.TravelItenariesCSV { //s.TravelItenariesCSV is a slice of the struct above        itenariesMap[v.FlightNum] = i    }utils.PrintExecutionTime(startTime)rest of the code

That should give you a better throughput estimate


Viewing all articles
Browse latest Browse all 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>