2017-09-21 11:13:13 -07:00
|
|
|
package benchmarks // nolint (goimports)
|
2015-12-01 20:12:01 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2017-10-04 13:40:45 -07:00
|
|
|
|
|
|
|
cmn "github.com/tendermint/tmlibs/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++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|