Skip to content

Instantly share code, notes, and snippets.

@up1
Last active August 14, 2025 04:55
Show Gist options
  • Select an option

  • Save up1/b031bc256ae39d4a364080a8a03e0e89 to your computer and use it in GitHub Desktop.

Select an option

Save up1/b031bc256ae39d4a364080a8a03e0e89 to your computer and use it in GitHub Desktop.
Go 1.25.0
# Update go 1.25
$go env -w GOTOOLCHAIN=go1.25.0
$go version
go version go1.25.0 darwin/arm64
# เปิด Go doc
$go doc -http
doc: Documentation server listening on addr http://localhost:61699
$GOEXPERIMENT=jsonv2 go test -bench=. -benchmem -count=3
goos: darwin
goarch: arm64
pkg: demo
cpu: Apple M2 Max
BenchmarkJsonV1Unmarshal-12 1884603 619.5 ns/op 128 B/op 3 allocs/op
BenchmarkJsonV1Unmarshal-12 1927093 616.4 ns/op 128 B/op 3 allocs/op
BenchmarkJsonV1Unmarshal-12 1927429 619.1 ns/op 128 B/op 3 allocs/op
BenchmarkJsonV2Unmarshal-12 2390827 504.4 ns/op 128 B/op 3 allocs/op
BenchmarkJsonV2Unmarshal-12 2394787 503.7 ns/op 128 B/op 3 allocs/op
BenchmarkJsonV2Unmarshal-12 2309986 503.6 ns/op 128 B/op 3 allocs/op
PASS
ok demo 10.824s
package demo_test
import (
"testing"
jsonv1 "encoding/json"
jsonv2 "encoding/json/v2"
)
type User struct {
ID int `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Tags []string `json:"tags"`
Active bool `json:"active"`
Created int64 `json:"created"`
}
var data = []byte(`{"id":1,"name":"Name 01","email":"[email protected]","tags":["tag1","tag2"],"active":true,"created":1625251200}`)
func BenchmarkJsonV1Unmarshal(b *testing.B) {
for range b.N {
var u User
_ = jsonv1.Unmarshal(data, &u)
}
}
func BenchmarkJsonV2Unmarshal(b *testing.B) {
for range b.N {
var u User
_ = jsonv2.Unmarshal(data, &u)
}
}
package main
import (
"fmt"
"sync"
)
var wg sync.WaitGroup
func main() {
wg.Go(func() {
fmt.Println("Process 1")
})
wg.Go(func() {
fmt.Println("Process 2")
})
wg.Wait()
fmt.Println("Finished all processes")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment