mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-29 23:30:04 +01:00
63d635a5e4
See ea9e2b19a5
41 lines
669 B
Go
41 lines
669 B
Go
package netstorage
|
|
|
|
import (
|
|
"math/rand"
|
|
"sync/atomic"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkConsistentHash(b *testing.B) {
|
|
nodes := []string{
|
|
"node1",
|
|
"node2",
|
|
"node3",
|
|
"node4",
|
|
}
|
|
rh := newConsistentHash(nodes, 0)
|
|
b.ReportAllocs()
|
|
b.SetBytes(int64(len(benchKeys)))
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
sum := 0
|
|
for pb.Next() {
|
|
for _, k := range benchKeys {
|
|
idx := rh.getNodeIdx(k, nil)
|
|
sum += idx
|
|
}
|
|
}
|
|
BenchSink.Add(uint64(sum))
|
|
})
|
|
}
|
|
|
|
var benchKeys = func() []uint64 {
|
|
r := rand.New(rand.NewSource(1))
|
|
keys := make([]uint64, 10000)
|
|
for i := 0; i < len(keys); i++ {
|
|
keys[i] = r.Uint64()
|
|
}
|
|
return keys
|
|
}()
|
|
|
|
var BenchSink atomic.Uint64
|