mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
identity: Add BenchmarkHashString
This commit is contained in:
parent
9989404d97
commit
3140e0b994
1 changed files with 24 additions and 0 deletions
|
@ -14,6 +14,9 @@
|
||||||
package identity
|
package identity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
qt "github.com/frankban/quicktest"
|
qt "github.com/frankban/quicktest"
|
||||||
|
@ -42,3 +45,24 @@ func (t tstKeyer) Key() string {
|
||||||
func (t tstKeyer) String() string {
|
func (t tstKeyer) String() string {
|
||||||
return "key: " + t.key
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue