MCPcopy Create free account
hub / github.com/dlclark/regexp2 / TestStringProcessingAllocations

Function TestStringProcessingAllocations

string_processing_test.go:227–247  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

225}
226
227func TestStringProcessingAllocations(t *testing.T) {
228 skipIfAllocsUnreliable(t)
229 re := MustCompile(`needle`)
230 input := "needle" + strings.Repeat("界", 21845)
231 if allocs := testing.AllocsPerRun(100, func() {
232 if _, err := re.FindAllStringIndex(input, 1); err != nil {
233 panic(err)
234 }
235 }); allocs > 5 {
236 t.Fatalf("FindAllStringIndex allocations=%v; want <=5", allocs)
237 }
238 split := MustCompile(`(,)`)
239 input = strings.Repeat("abc,", 1000) + "abc"
240 if allocs := testing.AllocsPerRun(100, func() {
241 if _, err := split.Split(input, -1); err != nil {
242 panic(err)
243 }
244 }); allocs > 30 {
245 t.Fatalf("Split allocations=%v; want <=30", allocs)
246 }
247}
248
249func TestSplitConcurrentPoolUse(t *testing.T) {
250 re := MustCompile(`(needle)`)

Callers

nothing calls this directly

Calls 4

skipIfAllocsUnreliableFunction · 0.85
SplitMethod · 0.80
MustCompileFunction · 0.70
FindAllStringIndexMethod · 0.65

Tested by

no test coverage detected