Skip to content

Commit

Permalink
Golang benchmarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed Mar 26, 2014
1 parent 5c601d5 commit d182c6b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
test
doc
tags
go
4 changes: 4 additions & 0 deletions golang/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
To run all benchmarks, make sure Go is installed run this in ./golang

go test -bench '.*'

44 changes: 44 additions & 0 deletions golang/main_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit d182c6b

Please sign in to comment.