-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprogress_bench_test.go
More file actions
98 lines (90 loc) · 1.96 KB
/
progress_bench_test.go
File metadata and controls
98 lines (90 loc) · 1.96 KB
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
package glyph
import (
"testing"
)
// progNode mimics SerialNode layout for progress
type progNode struct {
kind uint8
x, y, width int16
ratio float32
}
// BenchmarkProgressBarDirect measures raw WriteProgressBar performance
func BenchmarkProgressBarDirect(b *testing.B) {
nodes := make([]progNode, 100)
for j := 0; j < 100; j++ {
nodes[j] = progNode{
kind: 3,
x: int16((j % 10) * 10),
y: int16(j / 10),
width: 8,
ratio: float32(j) / 100.0,
}
}
buf := NewBuffer(100, 50)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
buf.ClearDirty()
for j := range nodes {
n := &nodes[j]
buf.WriteProgressBar(int(n.x), int(n.y), int(n.width), n.ratio, Style{})
}
}
}
// BenchmarkProgressBarNoClear measures without ClearDirty
func BenchmarkProgressBarNoClear(b *testing.B) {
nodes := make([]progNode, 100)
for j := 0; j < 100; j++ {
nodes[j] = progNode{
kind: 3,
x: int16((j % 10) * 10),
y: int16(j / 10),
width: 8,
ratio: float32(j) / 100.0,
}
}
buf := NewBuffer(100, 50)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for j := range nodes {
n := &nodes[j]
buf.WriteProgressBar(int(n.x), int(n.y), int(n.width), n.ratio, Style{})
}
}
}
// BenchmarkProgressBarSwitch mimics SerialTemplate's switch dispatch
func BenchmarkProgressBarSwitch(b *testing.B) {
const kindProgress = 3
type node struct {
kind uint8
W, H int16
X, Y int16
Text string
Ratio float32
Width int16
}
nodes := make([]node, 100)
for j := 0; j < 100; j++ {
nodes[j] = node{
kind: kindProgress,
X: int16((j % 10) * 10),
Y: int16(j / 10),
Width: 8,
Ratio: float32(j) / 100.0,
}
}
buf := NewBuffer(100, 50)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
buf.ClearDirty()
for j := range nodes {
n := &nodes[j]
switch {
case n.kind == kindProgress:
buf.WriteProgressBar(int(n.X), int(n.Y), int(n.Width), n.Ratio, Style{})
}
}
}
}