(b *testing.B)
| 485 | } |
| 486 | |
| 487 | func 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 | |
| 526 | func testReplacer() Replacer { |
| 527 | return Replacer{ |
nothing calls this directly
no test coverage detected