losvedir / transit-lang-cmp

Programming language comparison by reimplementing the same transit data app
MIT License
426 stars 29 forks source link

Go perf #18

Open CrimsonVoid opened 2 years ago

CrimsonVoid commented 2 years ago
k6 run -u 50 --duration 30s loadTest.js lang (branch) http_reqs/sec http_req_duration avg
go (main) 2,156 /s 22.67 ms
go (perf) 2,924 /s 16.78 ms
rust (main) 2,310 /s 21.13 ms
k6 run -u 50 --duration 30s loadTestSmallResponses.js lang (branch) http_reqs/sec http_req_duration avg
go (main) 7,728 /s 6.35 ms
go (perf) 16,244 /s 2.98 ms
rust (main) 13,387 /s 3.64 ms
csv load times filename go (main) go (perf) rust (main)
stop_times.txt 1.15 s 835 ms 677 ms
trips.txt 31 ms 30 ms 24 ms
CrimsonVoid commented 2 years ago

A little summary for some of the more notable commits:

sebnyberg commented 2 years ago

Did a similar refactor for fun that ended up almost identical to yours.

The only difference is that I went all the way and read the CSV contents into the exact form expected by the JSON encoder and compressed keys with fnv.

https://github.com/sebnyberg/transit-lang-cmp/blob/main/trogsit/app.go

benhoyt commented 1 year ago

@CrimsonVoid This is nice work and analysis! One thing to note is that you don't need a bufio.Reader when using csv.NewReader, because the first thing csv.NewReader does is wrap the input in a bufio.NewReader. See https://cs.opensource.google/go/go/+/refs/tags/go1.21.3:src/encoding/csv/reader.go;l=183