Skip to content

Benchmark yielding similar results against encoding/json #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nuric opened this issue Feb 7, 2025 · 0 comments
Open

Benchmark yielding similar results against encoding/json #534

nuric opened this issue Feb 7, 2025 · 0 comments

Comments

@nuric
Copy link

nuric commented Feb 7, 2025

Hello,

I'm probably missing something simple here. When I was trying to compare against standard library using the same large fixture:

func BenchmarkDecodeJSON(b *testing.B) {
	payload := ... // gojson.benchmark.LargeFixture
	for _, decodeLibrary := range []string{"encoding/json", "goccy/go-json"} {
		b.Run(decodeLibrary, func(b *testing.B) {
			for i := 0; i < b.N; i++ {
				// Unmarshal the payload
				var v map[string]any
				var err error
				switch decodeLibrary {
				case "encoding/json":
					err = json.Unmarshal(payload, &v)
				case "goccy/go-json":
					err = gojson.Unmarshal(payload, &v)
				}
				if err != nil {
					b.Fatal(err)
				}
			}
		})
	}
}

I get:

cpu: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
BenchmarkDecodeJSON/encoding/json-2         	    3286	    352568 ns/op	  209375 B/op	    2785 allocs/op
BenchmarkDecodeJSON/goccy/go-json-2         	    3772	    320198 ns/op	  249825 B/op	    3490 allocs/op
PASS

Is this not the same data used for the benchmarking in the README? I was expecting to a significant difference, especially for the large fixture payload in decoding.

Running them in seperate benchmarks (instead of using b.Run) gives the same results.

Thank for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant