github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xhash/ring/hash_test.go (about)

     1  package ring
     2  
     3  import (
     4  	"strconv"
     5  	"testing"
     6  )
     7  
     8  func TestGet(t *testing.T) {
     9  	m := New(100, nil)
    10  	m.Add("1", "2", "3", "4", "5")
    11  	counts := make(map[string]int, 5)
    12  	for i := 0; i < 1000000; i++ {
    13  		counts[m.Get(strconv.Itoa(i))]++
    14  	}
    15  	t.Logf("%+v\n", counts)
    16  }
    17  
    18  func BenchmarkGet(b *testing.B) {
    19  	m := New(100, nil)
    20  	m.Add("1", "2", "3", "4", "5")
    21  	b.ResetTimer()
    22  	b.ReportAllocs()
    23  	//b.ReportMetric(0, "op")
    24  	for i := 0; i < b.N; i++ {
    25  		m.Get(strconv.Itoa(i))
    26  	}
    27  }