Skip to content

Instantly share code, notes, and snippets.

@powerman
Created January 29, 2020 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save powerman/9919c143569bc08181bb2ae6b90ff1e7 to your computer and use it in GitHub Desktop.
Save powerman/9919c143569bc08181bb2ae6b90ff1e7 to your computer and use it in GitHub Desktop.
func BenchmarkJSON(b *testing.B) {
for i := 0; i < b.N; i++ {
obj := Object{}
if err := json.Unmarshal(testCase, &obj); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkFastJSON(b *testing.B) {
var p fastjson.Parser
for i := 0; i < b.N; i++ {
obj := Object{}
v, err := p.ParseBytes(testCase)
if err != nil {
b.Fatal(err)
}
obj.A, err = uuid.ParseBytes(v.GetStringBytes("A"))
if err != nil {
b.Fatal(err)
}
obj.B = v.GetFloat64("B")
obj.C = string(v.GetStringBytes("C"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment