Commit 04e0a762 authored by Russ Cox's avatar Russ Cox

hash/crc32: use sub-benchmarks

Change-Id: Iae68a097a6897f1616f94fdc3548837ef200e66f
Reviewed-on: https://go-review.googlesource.com/36541
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJoe Tsai <thebrokentoaster@gmail.com>
parent bd561699
......@@ -5,6 +5,7 @@
package crc32
import (
"fmt"
"hash"
"math/rand"
"testing"
......@@ -196,68 +197,28 @@ func TestGolden(t *testing.T) {
}
}
func BenchmarkIEEECrc40B(b *testing.B) {
benchmark(b, NewIEEE(), 40, 0)
func BenchmarkCRC32(b *testing.B) {
b.Run("poly=IEEE", benchmarkAll(NewIEEE()))
b.Run("poly=Castagnoli", benchmarkAll(New(MakeTable(Castagnoli))))
b.Run("poly=Koopman", benchmarkAll(New(MakeTable(Koopman))))
}
func BenchmarkIEEECrc1KB(b *testing.B) {
benchmark(b, NewIEEE(), 1<<10, 0)
}
func BenchmarkIEEECrc4KB(b *testing.B) {
benchmark(b, NewIEEE(), 4<<10, 0)
}
func BenchmarkIEEECrc32KB(b *testing.B) {
benchmark(b, NewIEEE(), 32<<10, 0)
}
func BenchmarkCastagnoliCrc15B(b *testing.B) {
benchmark(b, New(MakeTable(Castagnoli)), 15, 0)
}
func BenchmarkCastagnoliCrc15BMisaligned(b *testing.B) {
benchmark(b, New(MakeTable(Castagnoli)), 15, 1)
}
func BenchmarkCastagnoliCrc40B(b *testing.B) {
benchmark(b, New(MakeTable(Castagnoli)), 40, 0)
}
func BenchmarkCastagnoliCrc40BMisaligned(b *testing.B) {
benchmark(b, New(MakeTable(Castagnoli)), 40, 1)
}
func BenchmarkCastagnoliCrc512(b *testing.B) {
benchmark(b, New(MakeTable(Castagnoli)), 512, 0)
}
func BenchmarkCastagnoliCrc512Misaligned(b *testing.B) {
benchmark(b, New(MakeTable(Castagnoli)), 512, 1)
}
func BenchmarkCastagnoliCrc1KB(b *testing.B) {
benchmark(b, New(MakeTable(Castagnoli)), 1<<10, 0)
}
func BenchmarkCastagnoliCrc1KBMisaligned(b *testing.B) {
benchmark(b, New(MakeTable(Castagnoli)), 1<<10, 1)
}
func BenchmarkCastagnoliCrc4KB(b *testing.B) {
benchmark(b, New(MakeTable(Castagnoli)), 4<<10, 0)
}
func BenchmarkCastagnoliCrc4KBMisaligned(b *testing.B) {
benchmark(b, New(MakeTable(Castagnoli)), 4<<10, 1)
}
func BenchmarkCastagnoliCrc32KB(b *testing.B) {
benchmark(b, New(MakeTable(Castagnoli)), 32<<10, 0)
}
func BenchmarkCastagnoliCrc32KBMisaligned(b *testing.B) {
benchmark(b, New(MakeTable(Castagnoli)), 32<<10, 1)
func benchmarkAll(h hash.Hash32) func(b *testing.B) {
return func(b *testing.B) {
for _, size := range []int{15, 40, 512, 1 << 10, 4 << 10, 32 << 10} {
name := fmt.Sprint(size)
if size >= 1024 {
name = fmt.Sprintf("%dkB", size/1024)
}
b.Run("size="+name, func(b *testing.B) {
for align := 0; align <= 1; align++ {
b.Run(fmt.Sprintf("align=%d", align), func(b *testing.B) {
benchmark(b, h, int64(size), int64(align))
})
}
})
}
}
}
func benchmark(b *testing.B, h hash.Hash32, n, alignment int64) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment