public
Last active

  • Download Gist
benchmark results
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
jb@jborg-mbp:~/maps $ go test -bench .
testing: warning: no tests to run
PASS
BenchmarkArrayRead400k 100 13934553 ns/op
BenchmarkArrayRead410k 100 14369685 ns/op
BenchmarkArrayRead420k 100 14943785 ns/op
BenchmarkArrayRead430k 20 80558254 ns/op
BenchmarkArrayRead440k 50 65281578 ns/op
BenchmarkArrayRead450k 50 52350668 ns/op
BenchmarkArrayRead460k 50 42281165 ns/op
BenchmarkArrayRead470k 50 34521642 ns/op
BenchmarkArrayRead480k 100 26814710 ns/op
BenchmarkArrayRead490k 100 21991384 ns/op
BenchmarkArrayRead500k 100 18651190 ns/op
ok _/Users/jb/maps 40.475s
map_test.go
Go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
package map_test
 
import (
"bytes"
"math/rand"
"testing"
"time"
"runtime"
)
 
var r = rand.New(rand.NewSource(time.Now().UnixNano()))
 
func randomString() string {
var b bytes.Buffer
 
for i := 0; i < 16; i++ {
b.WriteByte(byte(0x61 + r.Intn(26)))
}
 
return b.String()
}
 
func BenchmarkArrayRead400k(b *testing.B) {
benchReads(400000, b)
}
 
func BenchmarkArrayRead410k(b *testing.B) {
benchReads(410000, b)
}
 
func BenchmarkArrayRead420k(b *testing.B) {
benchReads(420000, b)
}
 
func BenchmarkArrayRead430k(b *testing.B) {
benchReads(430000, b)
}
 
func BenchmarkArrayRead440k(b *testing.B) {
benchReads(440000, b)
}
 
func BenchmarkArrayRead450k(b *testing.B) {
benchReads(450000, b)
}
 
func BenchmarkArrayRead460k(b *testing.B) {
benchReads(460000, b)
}
 
func BenchmarkArrayRead470k(b *testing.B) {
benchReads(470000, b)
}
 
func BenchmarkArrayRead480k(b *testing.B) {
benchReads(480000, b)
}
 
func BenchmarkArrayRead490k(b *testing.B) {
benchReads(490000, b)
}
 
func BenchmarkArrayRead500k(b *testing.B) {
benchReads(500000, b)
}
 
func benchReads(size int, b *testing.B) {
m := makeMap(size)
runtime.GC()
b.ResetTimer()
for i := 0; i < b.N; i++ {
readMapRange(m)
}
}
 
func makeMap(size int) map[string]int64 {
m := make(map[string]int64)
for i := 0; i < size; i++ {
m[randomString()]++
}
return m
}
 
func readMapRange(m map[string]int64) {
totalInMap := 0
for k, v := range m {
if len(k) > 0 && v != 0 {
totalInMap++
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.