| 658 | } |
| 659 | |
| 660 | func BenchmarkTable(b *testing.B) { |
| 661 | for _, w := range [...]int{1, 10, 100} { |
| 662 | // Build a line with w cells. |
| 663 | line := bytes.Repeat([]byte("a\t"), w) |
| 664 | line = append(line, '\n') |
| 665 | for _, h := range [...]int{10, 1000, 100000} { |
| 666 | b.Run(fmt.Sprintf("%dx%d", w, h), func(b *testing.B) { |
| 667 | b.Run("new", func(b *testing.B) { |
| 668 | b.ReportAllocs() |
| 669 | for i := 0; i < b.N; i++ { |
| 670 | w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings |
| 671 | // Write the line h times. |
| 672 | for range h { |
| 673 | w.Write(line) |
| 674 | } |
| 675 | w.Flush() |
| 676 | } |
| 677 | }) |
| 678 | |
| 679 | b.Run("reuse", func(b *testing.B) { |
| 680 | b.ReportAllocs() |
| 681 | w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings |
| 682 | for i := 0; i < b.N; i++ { |
| 683 | // Write the line h times. |
| 684 | for range h { |
| 685 | w.Write(line) |
| 686 | } |
| 687 | w.Flush() |
| 688 | } |
| 689 | }) |
| 690 | }) |
| 691 | } |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | func BenchmarkPyramid(b *testing.B) { |
| 696 | for _, x := range [...]int{10, 100, 1000} { |