Files
EdgeNode/internal/grids/item_test.go

70 lines
1.3 KiB
Go
Raw Normal View History

2020-10-08 15:06:42 +08:00
package grids
import (
"crypto/md5"
2020-11-21 22:29:57 +08:00
"github.com/cespare/xxhash"
2020-10-08 15:06:42 +08:00
"strconv"
"testing"
)
func TestItem_Size(t *testing.T) {
item := &Item{
ValueInt64: 1024,
Key: []byte("123"),
ValueBytes: []byte("Hello, World"),
}
t.Log(item.Size())
}
func BenchmarkItem_Size(b *testing.B) {
item := &Item{
ValueInt64: 1024,
Key: []byte("123"),
ValueBytes: []byte("Hello, World"),
}
2020-11-21 22:29:57 +08:00
for i := 0; i < b.N; i++ {
2020-10-08 15:06:42 +08:00
_ = item.Size()
}
}
func TestItem_HashKey(t *testing.T) {
t.Log(HashKey([]byte("2")))
}
2020-11-21 22:29:57 +08:00
func TestItem_xxHash(t *testing.T) {
result := xxhash.Sum64([]byte("123456"))
2020-10-08 15:06:42 +08:00
t.Log(result)
}
func TestItem_unique(t *testing.T) {
m := map[uint64]bool{}
2020-11-21 22:29:57 +08:00
for i := 0; i < 1000*10000; i++ {
2020-10-08 15:06:42 +08:00
s := "Hello,World,LONG KEY,LONG KEY,LONG KEY,LONG KEY" + strconv.Itoa(i)
2020-11-21 22:29:57 +08:00
result := xxhash.Sum64([]byte(s))
2020-10-08 15:06:42 +08:00
_, ok := m[result]
if ok {
t.Log("found same", i)
break
} else {
m[result] = true
}
}
2020-11-21 22:29:57 +08:00
t.Log(xxhash.Sum64([]byte("01")))
t.Log(xxhash.Sum64([]byte("10")))
2020-10-08 15:06:42 +08:00
}
func BenchmarkItem_HashKeyMd5(b *testing.B) {
2020-11-21 22:29:57 +08:00
for i := 0; i < b.N; i++ {
2020-10-08 15:06:42 +08:00
h := md5.New()
h.Write([]byte("HELLO_KEY_" + strconv.Itoa(i)))
_ = h.Sum(nil)
}
}
2020-11-21 22:29:57 +08:00
func BenchmarkItem_xxHash(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = xxhash.Sum64([]byte("HELLO_KEY_" + strconv.Itoa(i)))
2020-10-08 15:06:42 +08:00
}
}