Skip to content

Commit

Permalink
benchmark: empty map traverse
Browse files Browse the repository at this point in the history
  • Loading branch information
lonng committed Aug 15, 2017
1 parent 4f22559 commit bbaa363
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package nano

import "testing"

func null(key, value int) int {
key += value
return key
}

func test1(m map[int]int) {
if len(m) < 1 {
return
}
for k, v := range m {
null(k, v)
}
}

func BenchmarkEmptyMap1(b *testing.B) {
b.ReportAllocs()

m := map[int]int{}
for i := 0; i < b.N; i++ {
test1(m)
}
}

func test2(m map[int]int) {
for k, v := range m {
null(k, v)
}
}

func BenchmarkEmptyMap2(b *testing.B) {
b.ReportAllocs()

m := map[int]int{}
for i := 0; i < b.N; i++ {
test2(m)
}
}

0 comments on commit bbaa363

Please sign in to comment.