Add a HashName benchmark

This commit is contained in:
Tom Thorogood 2018-11-29 10:28:29 +10:30
parent 1afd10068a
commit 2f8cf50b32
No known key found for this signature in database
GPG Key ID: 86C63CDA416C6D2F
1 changed files with 18 additions and 1 deletions

View File

@ -1,6 +1,9 @@
package dns
import "testing"
import (
"strconv"
"testing"
)
func TestPackNsec3(t *testing.T) {
nsec3 := HashName("dnsex.nl.", SHA1, 0, "DEAD")
@ -151,3 +154,17 @@ func TestNsec3EmptySalt(t *testing.T) {
t.Fatalf("expected record to match com. label")
}
}
func BenchmarkHashName(b *testing.B) {
for _, iter := range []uint16{
150, 2500, 5000, 10000, ^uint16(0),
} {
b.Run(strconv.Itoa(int(iter)), func(b *testing.B) {
for n := 0; n < b.N; n++ {
if HashName("some.example.org.", SHA1, iter, "deadbeef") == "" {
b.Fatalf("HashName failed")
}
}
})
}
}