aboutsummaryrefslogtreecommitdiffhomepage
path: root/identity
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-07-30 10:06:48 +0200
committerBjørn Erik Pedersen <[email protected]>2024-07-31 16:44:06 +0200
commit3140e0b994e4108220afedc3de8eaf42ff216904 (patch)
tree27974efda15dbf832d847766e0abf63141dfbbd7 /identity
parent9989404d974e6ebb5a3874c392e56884def44173 (diff)
downloadhugo-3140e0b994e4108220afedc3de8eaf42ff216904.tar.gz
hugo-3140e0b994e4108220afedc3de8eaf42ff216904.zip
identity: Add BenchmarkHashString
Diffstat (limited to 'identity')
-rw-r--r--identity/identityhash_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/identity/identityhash_test.go b/identity/identityhash_test.go
index 1ecaf7612..52debe293 100644
--- a/identity/identityhash_test.go
+++ b/identity/identityhash_test.go
@@ -14,6 +14,9 @@
package identity
import (
+ "fmt"
+ "math"
+ "strings"
"testing"
qt "github.com/frankban/quicktest"
@@ -42,3 +45,24 @@ func (t tstKeyer) Key() string {
func (t tstKeyer) String() string {
return "key: " + t.key
}
+
+func BenchmarkHashString(b *testing.B) {
+ word := " hello "
+
+ var tests []string
+
+ for i := 1; i <= 5; i++ {
+ sentence := strings.Repeat(word, int(math.Pow(4, float64(i))))
+ tests = append(tests, sentence)
+ }
+
+ b.ResetTimer()
+
+ for _, test := range tests {
+ b.Run(fmt.Sprintf("n%d", len(test)), func(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ HashString(test)
+ }
+ })
+ }
+}