all: add benchmarks and compare

This commit is contained in:
Aleksandr Razumov
2016-04-29 13:18:11 +03:00
parent 26f8320782
commit 7560d0b17b
3 changed files with 55 additions and 0 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ stun-typ-fuzz.zip
mem.out
benchmark.*.write
*.test
bench.go-*

View File

@@ -23,3 +23,7 @@ blackbox:
@TEST_EXTERNAL=1 go test -run TestClientSend -v
format:
goimports -w .
bench-compare:
go test -bench . > bench.go-16
go-tip test -bench . > bench.go-tip
@benchcmp bench.go-16 bench.go-tip

View File

@@ -2,6 +2,7 @@ package stun
import (
"testing"
"math/rand"
)
func TestXORSafe(t *testing.T) {
@@ -81,3 +82,52 @@ func TestXORFallback(t *testing.T) {
}
}
}
func BenchmarkXOR(b *testing.B) {
rand.Seed(666)
a := make([]byte, 1024)
c := make([]byte, 1024)
rand.Read(a)
rand.Read(c)
b.SetBytes(1024)
b.RunParallel(func(pb *testing.PB) {
dst := make([]byte, len(a))
for pb.Next() {
xorBytes(dst, a, c)
}
})
}
func BenchmarkXORSafe(b *testing.B) {
rand.Seed(666)
a := make([]byte, 1024)
c := make([]byte, 1024)
rand.Read(a)
rand.Read(c)
b.SetBytes(1024)
b.RunParallel(func(pb *testing.PB) {
dst := make([]byte, len(a))
for pb.Next() {
safeXORBytes(dst, a, c)
}
})
}
func BenchmarkXORFast(b *testing.B) {
if !supportsUnaligned {
b.Skip("No support for unaligned operations.")
}
rand.Seed(666)
a := make([]byte, 1024)
c := make([]byte, 1024)
rand.Read(a)
rand.Read(c)
b.SetBytes(1024)
b.RunParallel(func(pb *testing.PB) {
dst := make([]byte, len(a))
for pb.Next() {
fastXORBytes(dst, a, c)
}
})
}