diff options
Diffstat (limited to 'src/bytes/bytes_test.go')
| -rw-r--r-- | src/bytes/bytes_test.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/bytes/bytes_test.go b/src/bytes/bytes_test.go index 7263af3ed0..f58f18c461 100644 --- a/src/bytes/bytes_test.go +++ b/src/bytes/bytes_test.go @@ -1159,6 +1159,8 @@ type RepeatTest struct { count int } +var longString = "a" + string(make([]byte, 1<<16)) + "z" + var RepeatTests = []RepeatTest{ {"", "", 0}, {"", "", 1}, @@ -1167,6 +1169,9 @@ var RepeatTests = []RepeatTest{ {"-", "-", 1}, {"-", "----------", 10}, {"abc ", "abc abc abc ", 3}, + // Tests for results over the chunkLimit + {string(rune(0)), string(make([]byte, 1<<16)), 1 << 16}, + {longString, longString + longString, 2}, } func TestRepeat(t *testing.T) { @@ -2048,6 +2053,25 @@ func BenchmarkRepeat(b *testing.B) { } } +func BenchmarkRepeatLarge(b *testing.B) { + s := Repeat([]byte("@"), 8*1024) + for j := 8; j <= 30; j++ { + for _, k := range []int{1, 16, 4097} { + s := s[:k] + n := (1 << j) / k + if n == 0 { + continue + } + b.Run(fmt.Sprintf("%d/%d", 1<<j, k), func(b *testing.B) { + for i := 0; i < b.N; i++ { + Repeat(s, n) + } + b.SetBytes(int64(n * len(s))) + }) + } + } +} + func BenchmarkBytesCompare(b *testing.B) { for n := 1; n <= 2048; n <<= 1 { b.Run(fmt.Sprint(n), func(b *testing.B) { |
