This commit is contained in:
unknown
2026-02-04 20:27:13 +08:00
commit 3b042d1dad
9410 changed files with 1488147 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
package ttlcache_test
import (
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
"github.com/TeaOSLab/EdgeNode/internal/utils/ttlcache"
"github.com/TeaOSLab/EdgeNode/internal/utils/zero"
"github.com/cespare/xxhash/v2"
"runtime"
"strconv"
"testing"
)
func TestHashCollision(t *testing.T) {
var m = map[uint64]zero.Zero{}
var count = 1_000
if testutils.IsSingleTesting() {
count = 100_000_000
}
for i := 0; i < count; i++ {
var k = ttlcache.HashKeyString(strconv.Itoa(i))
_, ok := m[k]
if ok {
t.Fatal("collision at", i)
}
m[k] = zero.New()
}
t.Log(len(m), "elements")
}
func BenchmarkHashKey_Bytes(b *testing.B) {
runtime.GOMAXPROCS(1)
for i := 0; i < b.N; i++ {
ttlcache.HashKeyBytes([]byte("HELLO,WORLDHELLO,WORLDHELLO,WORLDHELLO,WORLDHELLO,WORLDHELLO,WORLD"))
}
}
func BenchmarkHashKey_String(b *testing.B) {
runtime.GOMAXPROCS(1)
for i := 0; i < b.N; i++ {
ttlcache.HashKeyString("HELLO,WORLDHELLO,WORLDHELLO,WORLDHELLO,WORLDHELLO,WORLDHELLO,WORLD")
}
}
func BenchmarkHashKey_XXHash(b *testing.B) {
runtime.GOMAXPROCS(1)
for i := 0; i < b.N; i++ {
xxhash.Sum64String("HELLO,WORLDHELLO,WORLDHELLO,WORLDHELLO,WORLDHELLO,WORLDHELLO,WORLD")
}
}