diff --git a/.gitignore b/.gitignore index 10147c3..efea881 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ test doc tags -go diff --git a/golang/README b/golang/README new file mode 100644 index 0000000..cc9d3ce --- /dev/null +++ b/golang/README @@ -0,0 +1,4 @@ +To run all benchmarks, make sure Go is installed run this in ./golang + + go test -bench '.*' + diff --git a/golang/main_test.go b/golang/main_test.go new file mode 100644 index 0000000..9150358 --- /dev/null +++ b/golang/main_test.go @@ -0,0 +1,44 @@ +package main + +import ( + "encoding/csv" + "io" + "log" + "os" + "testing" +) + +func BenchmarkShort(b *testing.B) { + for i := 0; i < b.N; i++ { + // Yes, this is including opening the file in the benchmark. + // But this is how it's done in the Rust benchmark too. + // Should convert to byte buffer in both... + readAll("../examples/data/short.csv") + } +} + +func BenchmarkMedium(b *testing.B) { + for i := 0; i < b.N; i++ { + // Yes, this is including opening the file in the benchmark. + // But this is how it's done in the Rust benchmark too. + // Should convert to byte buffer in both... + readAll("../examples/data/medium.csv") + } +} + +func readAll(fp string) { + f, err := os.Open(fp); + if err != nil { + log.Fatal(err) + } + csvr := csv.NewReader(f) + for { + _, err := csvr.Read() + if err != nil { + if err == io.EOF { + break + } + log.Fatal(err) + } + } +}