Skip to content
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

Valid too slow than std json #509

Open
forsaken628 opened this issue May 20, 2024 · 0 comments
Open

Valid too slow than std json #509

forsaken628 opened this issue May 20, 2024 · 0 comments

Comments

@forsaken628
Copy link

go version go1.22.0 linux/amd64

package test

import (
	"encoding/json"
	"testing"

	json2 "github.com/goccy/go-json"
)

func BenchmarkValid(b *testing.B) {
	data := `{"a":1}`
	b.Run("encoding/json", func(b *testing.B) {
		for range b.N {
			json.Valid([]byte(data))
		}
	})

	b.Run("goccy/go-json", func(b *testing.B) {
		for range b.N {
			json2.Valid([]byte(data))
		}
	})
}

/*
goos: linux
goarch: amd64
cpu: Intel(R) Core(TM) i3-9100F CPU @ 3.60GHz
=== RUN   BenchmarkValid
BenchmarkValid
=== RUN   BenchmarkValid/encoding/json
BenchmarkValid/encoding/json
BenchmarkValid/encoding/json-4          22184947                61.80 ns/op            0 B/op          0 allocs/op
=== RUN   BenchmarkValid/goccy/go-json
BenchmarkValid/goccy/go-json
BenchmarkValid/goccy/go-json-4           1413170               857.4 ns/op          1088 B/op         11 allocs/op
*/
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