diff options
| author | korzhao <korzhao95@gmail.com> | 2023-07-30 15:02:15 +0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-07-31 18:34:45 +0000 |
| commit | 1eaeec10958bf41d082ef212ee689fd8c1284320 (patch) | |
| tree | 8637669d6a3620c821ccefee3e16f09ef9eb0afe /src/encoding/json/bench_test.go | |
| parent | bac4e2f241ca8df3d5be6ddf83214b9a681f4086 (diff) | |
| download | go-1eaeec10958bf41d082ef212ee689fd8c1284320.tar.xz | |
encoding/json: optimize Unmarshal for maps
benchmark old ns/op new ns/op delta
BenchmarkUnmarshalMap-10 218 172 -21.28%
benchmark old allocs new allocs delta
BenchmarkUnmarshalMap-10 15 12 -20.00%
benchmark old bytes new bytes delta
BenchmarkUnmarshalMap-10 328 256 -21.95%
Change-Id: Ie20ab62731c752eb0040c6d1591fedd7d12b1e0c
Reviewed-on: https://go-review.googlesource.com/c/go/+/514100
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/encoding/json/bench_test.go')
| -rw-r--r-- | src/encoding/json/bench_test.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/encoding/json/bench_test.go b/src/encoding/json/bench_test.go index d3af0dc0ed..bafccdf193 100644 --- a/src/encoding/json/bench_test.go +++ b/src/encoding/json/bench_test.go @@ -385,6 +385,19 @@ func BenchmarkUnmarshalInt64(b *testing.B) { }) } +func BenchmarkUnmarshalMap(b *testing.B) { + b.ReportAllocs() + data := []byte(`{"key1":"value1","key2":"value2","key3":"value3"}`) + b.RunParallel(func(pb *testing.PB) { + x := make(map[string]string, 3) + for pb.Next() { + if err := Unmarshal(data, &x); err != nil { + b.Fatal("Unmarshal:", err) + } + } + }) +} + func BenchmarkIssue10335(b *testing.B) { b.ReportAllocs() j := []byte(`{"a":{ }}`) |
