github.com/evdatsion/aphelion-dpos-bft@v0.32.1/benchmarks/map_test.go (about)

     1  package benchmarks
     2  
     3  import (
     4  	"testing"
     5  
     6  	cmn "github.com/evdatsion/aphelion-dpos-bft/libs/common"
     7  )
     8  
     9  func BenchmarkSomething(b *testing.B) {
    10  	b.StopTimer()
    11  	numItems := 100000
    12  	numChecks := 100000
    13  	keys := make([]string, numItems)
    14  	for i := 0; i < numItems; i++ {
    15  		keys[i] = cmn.RandStr(100)
    16  	}
    17  	txs := make([]string, numChecks)
    18  	for i := 0; i < numChecks; i++ {
    19  		txs[i] = cmn.RandStr(100)
    20  	}
    21  	b.StartTimer()
    22  
    23  	counter := 0
    24  	for j := 0; j < b.N; j++ {
    25  		foo := make(map[string]string)
    26  		for _, key := range keys {
    27  			foo[key] = key
    28  		}
    29  		for _, tx := range txs {
    30  			if _, ok := foo[tx]; ok {
    31  				counter++
    32  			}
    33  		}
    34  	}
    35  }