Last active
August 14, 2025 04:55
-
-
Save up1/b031bc256ae39d4a364080a8a03e0e89 to your computer and use it in GitHub Desktop.
Go 1.25.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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