MCPcopy
hub / github.com/caddyserver/caddy / BenchmarkReplacer

Function BenchmarkReplacer

replacer_test.go:487–524  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

485}
486
487func BenchmarkReplacer(b *testing.B) {
488 type testCase struct {
489 name, input, empty string
490 }
491
492 rep := testReplacer()
493 rep.Set("str", "a string")
494 rep.Set("int", 123.456)
495
496 for _, bm := range []testCase{
497 {
498 name: "no placeholder",
499 input: `simple string`,
500 },
501 {
502 name: "string replacement",
503 input: `str={str}`,
504 },
505 {
506 name: "int replacement",
507 input: `int={int}`,
508 },
509 {
510 name: "placeholder",
511 input: `{"json": "object"}`,
512 },
513 {
514 name: "escaped placeholder",
515 input: `\{"json": \{"nested": "{bar}"\}\}`,
516 },
517 } {
518 b.Run(bm.name, func(b *testing.B) {
519 for b.Loop() {
520 rep.ReplaceAll(bm.input, bm.empty)
521 }
522 })
523 }
524}
525
526func testReplacer() Replacer {
527 return Replacer{

Callers

nothing calls this directly

Calls 3

testReplacerFunction · 0.85
ReplaceAllMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected