Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3594)

Delta Between Two Patch Sets: src/pkg/runtime/mapspeed_test.go

Issue 8056043: code review 8056043: runtime: Implement faster equals for strings and bytes. (Closed)
Left Patch Set: diff -r d040d5f08d5d https://khr%40golang.org@code.google.com/p/go/ Created 11 years ago
Right Patch Set: diff -r 52e3407d249f https://khr%40golang.org@code.google.com/p/go/ Created 10 years, 12 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/runtime/hashmap.c ('k') | src/pkg/runtime/runtime.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2013 The Go Authors. All rights reserved. 1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 package runtime_test 4 package runtime_test
5 5
6 import ( 6 import (
7 "fmt" 7 "fmt"
8 "strings" 8 "strings"
9 "testing" 9 "testing"
10 ) 10 )
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 func BenchmarkMegOneMap(b *testing.B) { 111 func BenchmarkMegOneMap(b *testing.B) {
112 m := make(map[string]bool) 112 m := make(map[string]bool)
113 m[strings.Repeat("X", 1<<20)] = true 113 m[strings.Repeat("X", 1<<20)] = true
114 key := strings.Repeat("Y", 1<<20) 114 key := strings.Repeat("Y", 1<<20)
115 b.ResetTimer() 115 b.ResetTimer()
116 for i := 0; i < b.N; i++ { 116 for i := 0; i < b.N; i++ {
117 _, _ = m[key] 117 _, _ = m[key]
118 } 118 }
119 } 119 }
120 120
121 func BenchmarkMegEqMap(b *testing.B) { 121 func BenchmarkMegEqMap(b *testing.B) {
bradfitz 2013/03/27 23:35:20 it's not clear what "Eq" in the benchmark names he
122 m := make(map[string]bool) 122 m := make(map[string]bool)
123 » m[strings.Repeat("X", 1<<20)] = true 123 » key1 := strings.Repeat("X", 1<<20)
124 » key := strings.Repeat("X", 1<<20-1) + "Y" 124 » key2 := strings.Repeat("X", 1<<20) // equal but different instance
125 » m[key1] = true
125 b.ResetTimer() 126 b.ResetTimer()
126 for i := 0; i < b.N; i++ { 127 for i := 0; i < b.N; i++ {
127 » » _, _ = m[key] 128 » » _, _ = m[key2]
128 } 129 }
129 } 130 }
130 131
131 func BenchmarkMegEmptyMap(b *testing.B) { 132 func BenchmarkMegEmptyMap(b *testing.B) {
132 m := make(map[string]bool) 133 m := make(map[string]bool)
133 key := strings.Repeat("X", 1<<20) 134 key := strings.Repeat("X", 1<<20)
134 b.ResetTimer() 135 b.ResetTimer()
135 for i := 0; i < b.N; i++ { 136 for i := 0; i < b.N; i++ {
136 _, _ = m[key] 137 _, _ = m[key]
137 } 138 }
138 } 139 }
139 140
140 func BenchmarkSmallStrMap(b *testing.B) { 141 func BenchmarkSmallStrMap(b *testing.B) {
141 m := make(map[string]bool) 142 m := make(map[string]bool)
142 for suffix := 'A'; suffix <= 'G'; suffix++ { 143 for suffix := 'A'; suffix <= 'G'; suffix++ {
143 m[fmt.Sprint(suffix)] = true 144 m[fmt.Sprint(suffix)] = true
144 } 145 }
145 key := "k" 146 key := "k"
146 b.ResetTimer() 147 b.ResetTimer()
147 for i := 0; i < b.N; i++ { 148 for i := 0; i < b.N; i++ {
148 _, _ = m[key] 149 _, _ = m[key]
149 } 150 }
150 } 151 }
152
151 func BenchmarkIntMap(b *testing.B) { 153 func BenchmarkIntMap(b *testing.B) {
152 m := make(map[int]bool) 154 m := make(map[int]bool)
153 for i := 0; i < 8; i++ { 155 for i := 0; i < 8; i++ {
154 m[i] = true 156 m[i] = true
155 } 157 }
156 b.ResetTimer() 158 b.ResetTimer()
157 for i := 0; i < b.N; i++ { 159 for i := 0; i < b.N; i++ {
158 _, _ = m[7] 160 _, _ = m[7]
159 } 161 }
160 } 162 }
163
164 // Accessing the same keys in a row.
165 func benchmarkRepeatedLookup(b *testing.B, lookupKeySize int) {
166 m := make(map[string]bool)
167 // At least bigger than a single bucket:
168 for i := 0; i < 64; i++ {
169 m[fmt.Sprintf("some key %d", i)] = true
170 }
171 base := strings.Repeat("x", lookupKeySize-1)
172 key1 := base + "1"
173 key2 := base + "2"
174 b.ResetTimer()
175 for i := 0; i < b.N/4; i++ {
176 _ = m[key1]
177 _ = m[key1]
178 _ = m[key2]
179 _ = m[key2]
180 }
181 }
182
183 func BenchmarkRepeatedLookupStrMapKey32(b *testing.B) { benchmarkRepeatedLookup( b, 32) }
184 func BenchmarkRepeatedLookupStrMapKey1M(b *testing.B) { benchmarkRepeatedLookup( b, 1<<20) }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b