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

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

Issue 8165044: code review 8165044: runtime: some addition map benchmarks (Closed)
Left Patch Set: Created 11 years, 11 months ago
Right Patch Set: diff -r 92913ac2c60f https://go.googlecode.com/hg/ Created 11 years, 11 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:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 m := make(map[string]bool) 131 m := make(map[string]bool)
132 for suffix := 'A'; suffix <= 'G'; suffix++ { 132 for suffix := 'A'; suffix <= 'G'; suffix++ {
133 m[fmt.Sprint(suffix)] = true 133 m[fmt.Sprint(suffix)] = true
134 } 134 }
135 key := "k" 135 key := "k"
136 b.ResetTimer() 136 b.ResetTimer()
137 for i := 0; i < b.N; i++ { 137 for i := 0; i < b.N; i++ {
138 _, _ = m[key] 138 _, _ = m[key]
139 } 139 }
140 } 140 }
141
141 func BenchmarkIntMap(b *testing.B) { 142 func BenchmarkIntMap(b *testing.B) {
142 m := make(map[int]bool) 143 m := make(map[int]bool)
143 for i := 0; i < 8; i++ { 144 for i := 0; i < 8; i++ {
144 m[i] = true 145 m[i] = true
145 } 146 }
146 b.ResetTimer() 147 b.ResetTimer()
147 for i := 0; i < b.N; i++ { 148 for i := 0; i < b.N; i++ {
148 _, _ = m[7] 149 _, _ = m[7]
149 } 150 }
150 } 151 }
152
153 // Accessing the same keys in a row.
154 func benchmarkRepeatedLookup(b *testing.B, lookupKeySize int) {
155 m := make(map[string]bool)
156 // At least bigger than a single bucket:
157 for i := 0; i < 64; i++ {
158 m[fmt.Sprintf("some key %d", i)] = true
159 }
160 base := strings.Repeat("x", lookupKeySize-1)
161 key1 := base + "1"
162 key2 := base + "2"
163 b.ResetTimer()
164 for i := 0; i < b.N/4; i++ {
165 _ = m[key1]
166 _ = m[key1]
167 _ = m[key2]
168 _ = m[key2]
169 }
170 }
171
172 func BenchmarkRepeatedLookupStrMapKey32(b *testing.B) { benchmarkRepeatedLookup( b, 32) }
173 func BenchmarkRepeatedLookupStrMapKey1M(b *testing.B) { benchmarkRepeatedLookup( b, 1<<20) }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

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