Skip to content

Commit

Permalink
identity: Add BenchmarkHashString
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Jul 31, 2024
1 parent 9989404 commit 3140e0b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions identity/identityhash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
package identity

import (
"fmt"
"math"
"strings"
"testing"

qt "github.com/frankban/quicktest"
Expand Down Expand Up @@ -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)
}
})
}
}

0 comments on commit 3140e0b

Please sign in to comment.