aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/map_benchmark_test.go
diff options
context:
space:
mode:
authorMartin Möhrmann <moehrmann@google.com>2018-10-22 20:45:04 +0200
committerMartin Möhrmann <martisch@uos.de>2018-10-23 06:31:13 +0000
commite85b8db604bd6dd84502708434a19596b54468b5 (patch)
tree275f47f2f62e2b55a5557718e57e9b8344b38d34 /src/runtime/map_benchmark_test.go
parent93eded02976e1bdfaddf3403fa415393f5b90378 (diff)
downloadgo-e85b8db604bd6dd84502708434a19596b54468b5.tar.gz
go-e85b8db604bd6dd84502708434a19596b54468b5.zip
runtime: use multiplication with overflow check for makemap
This improves performance for maps with a bucket size (key+value*8 bytes) larger than 32 bytes and removes loading a value from the maxElems array for smaller bucket sizes. name old time/op new time/op delta MakeMap/[Byte]Byte 93.5ns ± 1% 91.8ns ± 1% -1.83% (p=0.000 n=10+10) MakeMap/[Int]Int 134ns ± 1% 127ns ± 2% -5.61% (p=0.000 n=9+10) Updates #21588 Change-Id: I53f77186769c4bd0f2b90f3c6c17df643b060e39 Reviewed-on: https://go-review.googlesource.com/c/143797 Run-TryBot: Martin Möhrmann <martisch@uos.de> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/map_benchmark_test.go')
-rw-r--r--src/runtime/map_benchmark_test.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/runtime/map_benchmark_test.go b/src/runtime/map_benchmark_test.go
index 1d9d09c698..5681d5eeb8 100644
--- a/src/runtime/map_benchmark_test.go
+++ b/src/runtime/map_benchmark_test.go
@@ -228,6 +228,23 @@ func benchmarkRepeatedLookup(b *testing.B, lookupKeySize int) {
func BenchmarkRepeatedLookupStrMapKey32(b *testing.B) { benchmarkRepeatedLookup(b, 32) }
func BenchmarkRepeatedLookupStrMapKey1M(b *testing.B) { benchmarkRepeatedLookup(b, 1<<20) }
+func BenchmarkMakeMap(b *testing.B) {
+ b.Run("[Byte]Byte", func(b *testing.B) {
+ var m map[byte]byte
+ for i := 0; i < b.N; i++ {
+ m = make(map[byte]byte, 10)
+ }
+ hugeSink = m
+ })
+ b.Run("[Int]Int", func(b *testing.B) {
+ var m map[int]int
+ for i := 0; i < b.N; i++ {
+ m = make(map[int]int, 10)
+ }
+ hugeSink = m
+ })
+}
+
func BenchmarkNewEmptyMap(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {