mirror of
https://github.com/gortc/stun.git
synced 2025-09-26 20:41:36 +08:00
all: add benchmarks and compare
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ stun-typ-fuzz.zip
|
||||
mem.out
|
||||
benchmark.*.write
|
||||
*.test
|
||||
bench.go-*
|
||||
|
4
Makefile
4
Makefile
@@ -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
|
||||
|
50
xor_test.go
50
xor_test.go
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user