github.com/fufuok/utils@v1.0.10/xsync/util_hash_test.go (about)

     1  package xsync_test
     2  
     3  //lint:file-ignore U1000 unused fields are necessary to access the hasher
     4  //lint:file-ignore SA4000 hash code comparisons use identical expressions
     5  
     6  import (
     7  	"hash/maphash"
     8  	"testing"
     9  
    10  	. "github.com/fufuok/utils/xsync"
    11  )
    12  
    13  func BenchmarkMapHashString(b *testing.B) {
    14  	fn := func(seed maphash.Seed, s string) uint64 {
    15  		var h maphash.Hash
    16  		h.SetSeed(seed)
    17  		h.WriteString(s)
    18  		return h.Sum64()
    19  	}
    20  	seed := maphash.MakeSeed()
    21  	for i := 0; i < b.N; i++ {
    22  		_ = fn(seed, benchmarkKeyPrefix)
    23  	}
    24  	// about 13ns/op on x86-64
    25  }
    26  
    27  func BenchmarkHashString(b *testing.B) {
    28  	seed := MakeSeed()
    29  	for i := 0; i < b.N; i++ {
    30  		_ = HashString(benchmarkKeyPrefix, seed)
    31  	}
    32  	// about 4ns/op on x86-64
    33  }