aboutsummaryrefslogtreecommitdiff
path: root/src/bytes
diff options
context:
space:
mode:
Diffstat (limited to 'src/bytes')
-rw-r--r--src/bytes/compare_test.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/bytes/compare_test.go b/src/bytes/compare_test.go
index a595d575d0..a0150abd99 100644
--- a/src/bytes/compare_test.go
+++ b/src/bytes/compare_test.go
@@ -6,6 +6,7 @@ package bytes_test
import (
. "bytes"
+ "fmt"
"internal/testenv"
"testing"
)
@@ -213,22 +214,30 @@ func BenchmarkCompareBytesDifferentLength(b *testing.B) {
}
}
-func BenchmarkCompareBytesBigUnaligned(b *testing.B) {
+func benchmarkCompareBytesBigUnaligned(b *testing.B, offset int) {
b.StopTimer()
b1 := make([]byte, 0, 1<<20)
for len(b1) < 1<<20 {
b1 = append(b1, "Hello Gophers!"...)
}
- b2 := append([]byte("hello"), b1...)
+ b2 := append([]byte("12345678")[:offset], b1...)
b.StartTimer()
- for i := 0; i < b.N; i++ {
- if Compare(b1, b2[len("hello"):]) != 0 {
+ for j := 0; j < b.N; j++ {
+ if Compare(b1, b2[offset:]) != 0 {
b.Fatal("b1 != b2")
}
}
b.SetBytes(int64(len(b1)))
}
+func BenchmarkCompareBytesBigUnaligned(b *testing.B) {
+ for i := 1; i < 8; i++ {
+ b.Run(fmt.Sprintf("offset=%d", i), func(b *testing.B) {
+ benchmarkCompareBytesBigUnaligned(b, i)
+ })
+ }
+}
+
func BenchmarkCompareBytesBig(b *testing.B) {
b.StopTimer()
b1 := make([]byte, 0, 1<<20)