tendermint/benchmarks/map_test.go

36 lines
617 B
Go
Raw Normal View History

package benchmarks
2015-12-01 20:12:01 -08:00
import (
"testing"
2017-10-04 13:40:45 -07:00
2018-07-01 19:36:49 -07:00
cmn "github.com/tendermint/tendermint/libs/common"
2015-12-01 20:12:01 -08:00
)
func BenchmarkSomething(b *testing.B) {
b.StopTimer()
numItems := 100000
numChecks := 100000
keys := make([]string, numItems)
for i := 0; i < numItems; i++ {
2017-10-04 13:40:45 -07:00
keys[i] = cmn.RandStr(100)
2015-12-01 20:12:01 -08:00
}
txs := make([]string, numChecks)
for i := 0; i < numChecks; i++ {
2017-10-04 13:40:45 -07:00
txs[i] = cmn.RandStr(100)
2015-12-01 20:12:01 -08:00
}
b.StartTimer()
counter := 0
for j := 0; j < b.N; j++ {
foo := make(map[string]string)
for _, key := range keys {
foo[key] = key
}
for _, tx := range txs {
if _, ok := foo[tx]; ok {
counter++
}
}
}
}