]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
identity: Add BenchmarkHashString
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 30 Jul 2024 08:06:48 +0000 (10:06 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 31 Jul 2024 14:44:06 +0000 (16:44 +0200)
identity/identityhash_test.go

index 1ecaf7612457189ac94f79a7625417bdd667489c..52debe293f227b1f9b5b6ce3701ac7c09fe993b3 100644 (file)
@@ -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)
+                       }
+               })
+       }
+}