2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2018-02-24 17:24:12 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
2019-02-02 16:18:25 +08:00
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2018-02-24 17:24:12 +08:00
|
|
|
|
|
|
|
// go test *.go -bench=".*"
|
|
|
|
|
|
|
|
package ghash_test
|
|
|
|
|
|
|
|
import (
|
2019-06-19 09:06:52 +08:00
|
|
|
"testing"
|
2019-07-29 21:01:19 +08:00
|
|
|
|
2021-10-11 21:41:56 +08:00
|
|
|
"github.com/gogf/gf/v2/encoding/ghash"
|
2018-12-04 19:26:46 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-06-19 09:06:52 +08:00
|
|
|
str = []byte("This is the test string for hash.")
|
2018-02-24 17:24:12 +08:00
|
|
|
)
|
|
|
|
|
2022-01-13 21:31:23 +08:00
|
|
|
func Benchmark_BKDR(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.BKDR(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 21:31:23 +08:00
|
|
|
func Benchmark_BKDR64(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.BKDR64(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 21:31:23 +08:00
|
|
|
func Benchmark_SDBM(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.SDBM(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 21:31:23 +08:00
|
|
|
func Benchmark_SDBM64(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.SDBM64(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 21:31:23 +08:00
|
|
|
func Benchmark_RS(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.RS(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|
|
|
|
|
2022-04-19 16:18:49 +08:00
|
|
|
func Benchmark_RS64(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.RS64(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 21:31:23 +08:00
|
|
|
func Benchmark_JS(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.JS(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 21:31:23 +08:00
|
|
|
func Benchmark_JS64(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.JS64(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 21:31:23 +08:00
|
|
|
func Benchmark_PJW(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.PJW(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 21:31:23 +08:00
|
|
|
func Benchmark_PJW64(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.PJW64(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 21:31:23 +08:00
|
|
|
func Benchmark_ELF(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.ELF(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 21:31:23 +08:00
|
|
|
func Benchmark_ELF64(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.ELF64(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 21:31:23 +08:00
|
|
|
func Benchmark_DJB(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.DJB(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 21:31:23 +08:00
|
|
|
func Benchmark_DJB64(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.DJB64(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 21:31:23 +08:00
|
|
|
func Benchmark_AP(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.AP(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 21:31:23 +08:00
|
|
|
func Benchmark_AP64(b *testing.B) {
|
2019-06-19 09:06:52 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2022-01-13 21:31:23 +08:00
|
|
|
ghash.AP64(str)
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2018-02-24 17:24:12 +08:00
|
|
|
}
|