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
void
runtime·mapiterinit(MapType *t, Hmap *h, struct hash_iter *it)
{
- if(h == nil) {
+ if(h == nil || h->count == 0) {
it->key = nil;
return;
}
_ = 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 {
+ }
+ }
+}