Skip to content

Commit

Permalink
Compare against BurntSushi's TOML
Browse files Browse the repository at this point in the history
BenchmarkUnmarshalToml-8             1000  1320117 ns/op  450932 B/op  15072 allocs/op
BenchmarkUnmarshalBurntSushiToml-8   3000   402897 ns/op   82900 B/op   1761 allocs/op
BenchmarkUnmarshalJson-8            20000    66092 ns/op    3536 B/op    101 allocs/op
BenchmarkUnmarshalYaml-8            10000   189600 ns/op   44872 B/op   1058 allocs/op
  • Loading branch information
pelletier committed Jun 2, 2017
1 parent fdb3cf6 commit 906300b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 17 additions & 1 deletion benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"
"time"

burntsushi "github.com/BurntSushi/toml"
yaml "gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -95,7 +96,7 @@ type benchmarkDoc struct {
Key1 []int64
Key2 []string
Key3 [][]int64
// TODO: Key4
// TODO: Key4 not supported by go-toml's Unmarshal
Key5 []int64
Key6 []int64
}
Expand Down Expand Up @@ -145,6 +146,21 @@ func BenchmarkUnmarshalToml(b *testing.B) {
}
}

func BenchmarkUnmarshalBurntSushiToml(b *testing.B) {
bytes, err := ioutil.ReadFile("benchmark.toml")
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
target := benchmarkDoc{}
err := burntsushi.Unmarshal(bytes, &target)
if err != nil {
b.Fatal(err)
}
}
}

func BenchmarkUnmarshalJson(b *testing.B) {
bytes, err := ioutil.ReadFile("benchmark.json")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ go vet ./...
go get github.com/pelletier/go-buffruneio
go get github.com/davecgh/go-spew/spew
go get gopkg.in/yaml.v2
go get github.com/BurntSushi/toml

# get code for BurntSushi TOML validation
# pinning all to 'HEAD' for version 0.3.x work (TODO: pin to commit hash when tests stabilize)
Expand Down

0 comments on commit 906300b

Please sign in to comment.