(b *testing.B)
| 553 | } |
| 554 | |
| 555 | func Benchmark_LogfKeyAndValues(b *testing.B) { |
| 556 | tests := []struct { |
| 557 | name string |
| 558 | format string |
| 559 | keysAndValues []any |
| 560 | level Level |
| 561 | }{ |
| 562 | { |
| 563 | name: "test logf with debug level and key-values", |
| 564 | level: LevelDebug, |
| 565 | format: "", |
| 566 | keysAndValues: []any{"name", "Bob", "age", 30}, |
| 567 | }, |
| 568 | { |
| 569 | name: "test logf with info level and key-values", |
| 570 | level: LevelInfo, |
| 571 | format: "", |
| 572 | keysAndValues: []any{"status", "ok", "code", 200}, |
| 573 | }, |
| 574 | { |
| 575 | name: "test logf with warn level and key-values", |
| 576 | level: LevelWarn, |
| 577 | format: "", |
| 578 | keysAndValues: []any{"error", "not found", "id", 123}, |
| 579 | }, |
| 580 | { |
| 581 | name: "test logf with format and key-values", |
| 582 | level: LevelWarn, |
| 583 | format: "test", |
| 584 | keysAndValues: []any{"error", "not found", "id", 123}, |
| 585 | }, |
| 586 | { |
| 587 | name: "test logf with one key", |
| 588 | level: LevelWarn, |
| 589 | format: "", |
| 590 | keysAndValues: []any{"error"}, |
| 591 | }, |
| 592 | } |
| 593 | |
| 594 | for _, tt := range tests { |
| 595 | b.Run(tt.name, func(bb *testing.B) { |
| 596 | var buf bytes.Buffer |
| 597 | l := &defaultLogger{ |
| 598 | stdlog: log.New(&buf, "", 0), |
| 599 | level: tt.level, |
| 600 | depth: 4, |
| 601 | } |
| 602 | |
| 603 | bb.ReportAllocs() |
| 604 | |
| 605 | for bb.Loop() { |
| 606 | l.privateLogw(tt.level, tt.format, tt.keysAndValues) |
| 607 | } |
| 608 | }) |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | func Benchmark_LogfKeyAndValues_Parallel(b *testing.B) { |
nothing calls this directly
no test coverage detected