diff options
Diffstat (limited to 'src/strings/strings_test.go')
| -rw-r--r-- | src/strings/strings_test.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/strings/strings_test.go b/src/strings/strings_test.go index 210bd9e44b..27489c2d16 100644 --- a/src/strings/strings_test.go +++ b/src/strings/strings_test.go @@ -1105,6 +1105,8 @@ func TestCaseConsistency(t *testing.T) { */ } +var longString = "a" + string(make([]byte, 1<<16)) + "z" + var RepeatTests = []struct { in, out string count int @@ -1116,6 +1118,9 @@ var RepeatTests = []struct { {"-", "-", 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) { @@ -1885,6 +1890,25 @@ func BenchmarkRepeat(b *testing.B) { } } +func BenchmarkRepeatLarge(b *testing.B) { + s := Repeat("@", 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 BenchmarkIndexAnyASCII(b *testing.B) { x := Repeat("#", 2048) // Never matches set cs := "0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz" |
