-
Notifications
You must be signed in to change notification settings - Fork 119
/
bench_test.go
95 lines (84 loc) · 2.44 KB
/
bench_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
package gopretty
import (
"io"
"testing"
"time"
"github.com/jedib0t/go-pretty/v6/list"
"github.com/jedib0t/go-pretty/v6/progress"
"github.com/jedib0t/go-pretty/v6/table"
)
var (
listItem1 = "Game Of Thrones"
listItems2 = []interface{}{"Winter", "Is", "Coming"}
listItems3 = []interface{}{"This", "Is", "Known"}
tableCaption = "table-caption"
tableRowFooter = table.Row{"", "", "Total", 10000}
tableRowHeader = table.Row{"#", "First Name", "Last Name", "Salary"}
tableRows = []table.Row{
{1, "Arya", "Stark", 3000},
{20, "Jon", "Snow", 2000, "You know nothing, Jon Snow!"},
{300, "Tyrion", "Lannister", 5000},
}
tracker1 = progress.Tracker{Message: "Calculating Total # 1", Total: 1000, Units: progress.UnitsDefault}
tracker2 = progress.Tracker{Message: "Downloading File # 2", Total: 1000, Units: progress.UnitsBytes}
tracker3 = progress.Tracker{Message: "Transferring Amount # 3", Total: 1000, Units: progress.UnitsCurrencyDollar}
)
func BenchmarkList_Render(b *testing.B) {
for i := 0; i < b.N; i++ {
lw := list.NewWriter()
lw.AppendItem(listItem1)
lw.Indent()
lw.AppendItems(listItems2)
lw.Indent()
lw.AppendItems(listItems3)
lw.Render()
}
}
func BenchmarkProgress_Render(b *testing.B) {
trackSomething := func(pw progress.Writer, tracker *progress.Tracker) {
tracker.Reset()
pw.AppendTracker(tracker)
time.Sleep(time.Millisecond * 100)
tracker.Increment(tracker.Total / 2)
time.Sleep(time.Millisecond * 100)
tracker.Increment(tracker.Total / 2)
}
for i := 0; i < b.N; i++ {
pw := progress.NewWriter()
pw.SetAutoStop(true)
pw.SetOutputWriter(io.Discard)
go trackSomething(pw, &tracker1)
go trackSomething(pw, &tracker2)
go trackSomething(pw, &tracker3)
time.Sleep(time.Millisecond * 50)
pw.Render()
}
}
func generateBenchmarkTable() table.Writer {
tw := table.NewWriter()
tw.AppendHeader(tableRowHeader)
tw.AppendRows(tableRows)
tw.AppendFooter(tableRowFooter)
tw.SetCaption(tableCaption)
return tw
}
func BenchmarkTable_Render(b *testing.B) {
for i := 0; i < b.N; i++ {
generateBenchmarkTable().Render()
}
}
func BenchmarkTable_RenderCSV(b *testing.B) {
for i := 0; i < b.N; i++ {
generateBenchmarkTable().RenderCSV()
}
}
func BenchmarkTable_RenderHTML(b *testing.B) {
for i := 0; i < b.N; i++ {
generateBenchmarkTable().RenderHTML()
}
}
func BenchmarkTable_RenderMarkdown(b *testing.B) {
for i := 0; i < b.N; i++ {
generateBenchmarkTable().RenderMarkdown()
}
}