-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbenchmarks_test.go
109 lines (93 loc) · 2.86 KB
/
benchmarks_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package simpletable
import (
"fmt"
"testing"
)
var (
benchStyleData = [][]interface{}{
{1, "Newton G. Goetz", "252-585-5166", "[email protected]", 10},
{2, "Rebecca R. Edney", "865-475-4171", "[email protected]", 12},
{3, "John R. Jackson", "810-325-1417", "[email protected]", 15},
{4, "Ron J. Gomes", "217-450-8568", "[email protected]", 25},
{5, "Penny R. Lewis", "870-794-1666", "[email protected]", 5},
{6, "Sofia J. Smith", "770-333-7379", "[email protected]", 3},
{7, "Karlene D. Owen", "231-242-4157", "[email protected]", 12},
{8, "Daniel L. Love", "978-210-4178", "[email protected]", 44},
{9, "Julie T. Dial", "719-966-5354", "[email protected]", 8},
{10, "Juan J. Kennedy", "908-910-8893", "[email protected]", 16},
}
benchStyleDefaultTable = benchStyleTable(StyleDefault)
benchStyleCompactTable = benchStyleTable(StyleCompact)
benchStyleCompactLiteTable = benchStyleTable(StyleCompactLite)
benchStyleCompactClassicTable = benchStyleTable(StyleCompactClassic)
benchStyleMarkdownTable = benchStyleTable(StyleMarkdown)
benchStyleRoundedTable = benchStyleTable(StyleRounded)
benchStyleUnicodeTable = benchStyleTable(StyleUnicode)
)
func BenchmarkStyleDefault(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = benchStyleDefaultTable.String()
}
}
func BenchmarkStyleCompact(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = benchStyleCompactTable.String()
}
}
func BenchmarkStyleCompactLite(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = benchStyleCompactLiteTable.String()
}
}
func BenchmarkStyleCompactClassic(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = benchStyleCompactClassicTable.String()
}
}
func BenchmarkStyleMarkdown(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = benchStyleMarkdownTable.String()
}
}
func BenchmarkStyleRounded(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = benchStyleRoundedTable.String()
}
}
func BenchmarkStyleUnicode(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = benchStyleUnicodeTable.String()
}
}
func benchStyleTable(s *Style) *Table {
t := New()
t.SetStyle(s)
t.Header = &Header{
Cells: []*Cell{
{Align: AlignCenter, Text: "#"},
{Align: AlignCenter, Text: "NAME"},
{Align: AlignCenter, Text: "PHONE"},
{Align: AlignCenter, Text: "EMAIL"},
{Align: AlignCenter, Text: "QTTY"},
},
}
subtotal := 0
for _, row := range benchStyleData {
r := []*Cell{
{Align: AlignRight, Text: fmt.Sprintf("%d", row[0].(int))},
{Text: row[1].(string)},
{Text: row[2].(string)},
{Text: row[3].(string)},
{Align: AlignRight, Text: fmt.Sprintf("%d", row[4])},
}
t.Body.Cells = append(t.Body.Cells, r)
subtotal += row[4].(int)
}
t.Footer = &Footer{
Cells: []*Cell{
{Align: AlignRight, Span: 4, Text: "Subtotal"},
{Align: AlignRight, Text: fmt.Sprintf("%d", subtotal)},
},
}
return t
}