github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/fnv/hash_test.go (about)

     1  // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
     2  
     3  package fnv_test
     4  
     5  import (
     6  	"github.com/TeaOSLab/EdgeNode/internal/utils/fnv"
     7  	"github.com/iwind/TeaGo/types"
     8  	"testing"
     9  )
    10  
    11  func TestHash(t *testing.T) {
    12  	for _, key := range []string{"costarring", "liquid", "hello"} {
    13  		var h = fnv.HashString(key)
    14  		t.Log(key + " => " + types.String(h))
    15  	}
    16  }
    17  
    18  func BenchmarkHashString(b *testing.B) {
    19  	b.RunParallel(func(pb *testing.PB) {
    20  		for pb.Next() {
    21  			_ = fnv.HashString("abcdefh")
    22  		}
    23  	})
    24  }
    25  
    26  func BenchmarkHashString_Long(b *testing.B) {
    27  	b.RunParallel(func(pb *testing.PB) {
    28  		for pb.Next() {
    29  			_ = fnv.HashString("HELLO,WORLDHELLO,WORLDHELLO,WORLDHELLO,WORLDHELLO,WORLDHELLO,WORLD")
    30  		}
    31  	})
    32  }