Commit 7b9df092 authored by Frederick Kelly Mayle III's avatar Frederick Kelly Mayle III Committed by Brad Fitzpatrick

runtime: faster range on empty map

benchmark                old ns/op    new ns/op    delta
BenchmarkMapIter               191          190   -0.52%
BenchmarkMapIterEmpty           22            4  -78.96%

R=golang-dev, minux.ma, dvyukov, iant, khr
CC=golang-dev
https://golang.org/cl/9637043
parent c6b6c4ac
......@@ -1355,7 +1355,7 @@ reflect·mapassign(MapType *t, Hmap *h, uintptr key, uintptr val, bool pres)
void
runtime·mapiterinit(MapType *t, Hmap *h, struct hash_iter *it)
{
if(h == nil) {
if(h == nil || h->count == 0) {
it->key = nil;
return;
}
......
......@@ -233,3 +233,24 @@ func BenchmarkNewEmptyMap(b *testing.B) {
_ = make(map[int]int)
}
}
func BenchmarkMapIter(b *testing.B) {
m := make(map[int]bool)
for i := 0; i < 8; i++ {
m[i] = true
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, _ = range m {
}
}
}
func BenchmarkMapIterEmpty(b *testing.B) {
m := make(map[int]bool)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, _ = range m {
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment