github.com/jxskiss/gopkg@v0.17.3/rthash/hash_test.go (about) 1 package rthash 2 3 import ( 4 "fmt" 5 "log" 6 "math/rand" 7 "testing" 8 ) 9 10 func TestHash(t *testing.T) { 11 cases := []interface{}{ 12 "abc", 13 int8(19), 14 uint8(19), 15 int16(12345), 16 uint16(12345), 17 int32(8484848), 18 uint32(8484848), 19 int64(1234567890), 20 uint64(1234567890), 21 int(1234567890), 22 uint64(1234567890), 23 uintptr(1234567890), 24 float32(1.1314), 25 float64(1.1314), 26 complex(float32(1.1314), float32(1.1314)), 27 complex(float64(1.1314), float64(1.1314)), 28 hashable{1234, "1234"}, 29 } 30 31 var h = New() 32 for _, x := range cases { 33 hash := h.Hash(x) 34 log.Println(fmt.Sprintf("%T: %v, hash: %d", x, x, hash)) 35 } 36 } 37 38 type hashable struct { 39 A int 40 B string 41 } 42 43 func BenchmarkHash_Int64(b *testing.B) { 44 h := New() 45 x := rand.Int63() 46 for i := 0; i < b.N; i++ { 47 _ = h.Int64(x) 48 } 49 } 50 51 func BenchmarkHash_Bytes(b *testing.B) { 52 h := New() 53 x := []byte("this is a short sample text") 54 for i := 0; i < b.N; i++ { 55 _ = h.Bytes(x) 56 } 57 }