diff options
Diffstat (limited to 'src/pkg/runtime/string_test.go')
| -rw-r--r-- | src/pkg/runtime/string_test.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/pkg/runtime/string_test.go b/src/pkg/runtime/string_test.go index 6ba3c1d292..df3ff06a7d 100644 --- a/src/pkg/runtime/string_test.go +++ b/src/pkg/runtime/string_test.go @@ -47,3 +47,31 @@ func BenchmarkCompareStringDifferentLength(b *testing.B) { } } } + +func BenchmarkCompareStringBigUnaligned(b *testing.B) { + bytes := make([]byte, 0, 1<<20) + for len(bytes) < 1<<20 { + bytes = append(bytes, "Hello Gophers!"...) + } + s1, s2 := string(bytes), "hello"+string(bytes) + for i := 0; i < b.N; i++ { + if s1 != s2[len("hello"):] { + b.Fatal("s1 != s2") + } + } + b.SetBytes(int64(len(s1))) +} + +func BenchmarkCompareStringBig(b *testing.B) { + bytes := make([]byte, 0, 1<<20) + for len(bytes) < 1<<20 { + bytes = append(bytes, "Hello Gophers!"...) + } + s1, s2 := string(bytes), string(bytes) + for i := 0; i < b.N; i++ { + if s1 != s2 { + b.Fatal("s1 != s2") + } + } + b.SetBytes(int64(len(s1))) +} |
