Skip to content

Instantly share code, notes, and snippets.

@kaneshin
Created July 6, 2016 10:02
Show Gist options
  • Save kaneshin/9afe28017f9cdbb1e1bad141519414c3 to your computer and use it in GitHub Desktop.
Save kaneshin/9afe28017f9cdbb1e1bad141519414c3 to your computer and use it in GitHub Desktop.
var jsonData = []byte(`{"foo":true,"bar":1,"hoge":"hogehoge"}`)
var data map[string]interface{}
func BenchmarkUnmarshal(b *testing.B) {
for n := 0; n < b.N; n++ {
json.Unmarshal(jsonData, &data)
}
}
var buf bytes.Buffer
func init() {
buf.Write([]byte(`{"foo":true,"bar":1,"hoge":"hogehoge"}`))
}
func BenchmarkDecoder(b *testing.B) {
for n := 0; n < b.N; n++ {
json.NewDecoder(&buf).Decode(&data)
}
}
@kaneshin
Copy link
Author

kaneshin commented Jul 6, 2016

BenchmarkUnmarshal-2      300000              4632 ns/op     496 B/op         19 allocs/op
BenchmarkDecoder-2       3000000               491 ns/op     928 B/op          2 allocs/op

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment