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
|
package mpb_test
import (
"io"
"sync"
"testing"
"github.com/vbauerster/mpb/v8"
)
const total = 1000
func BenchmarkNopStyle1Bar(b *testing.B) {
bench(b, mpb.NopStyle(), false, 1)
}
func BenchmarkNopStyle1BarWithAutoRefresh(b *testing.B) {
bench(b, mpb.NopStyle(), true, 1)
}
func BenchmarkNopStyle2Bars(b *testing.B) {
bench(b, mpb.NopStyle(), false, 2)
}
func BenchmarkNopStyle2BarsWithAutoRefresh(b *testing.B) {
bench(b, mpb.NopStyle(), true, 2)
}
func BenchmarkNopStyle3Bars(b *testing.B) {
bench(b, mpb.NopStyle(), false, 3)
}
func BenchmarkNopStyle3BarsWithAutoRefresh(b *testing.B) {
bench(b, mpb.NopStyle(), true, 3)
}
func BenchmarkBarStyle1Bar(b *testing.B) {
bench(b, mpb.BarStyle(), false, 1)
}
func BenchmarkBarStyle1BarWithAutoRefresh(b *testing.B) {
bench(b, mpb.BarStyle(), true, 1)
}
func BenchmarkBarStyle2Bars(b *testing.B) {
bench(b, mpb.BarStyle(), false, 2)
}
func BenchmarkBarStyle2BarsWithAutoRefresh(b *testing.B) {
bench(b, mpb.BarStyle(), true, 2)
}
func BenchmarkBarStyle3Bars(b *testing.B) {
bench(b, mpb.BarStyle(), false, 3)
}
func BenchmarkBarStyle3BarsWithAutoRefresh(b *testing.B) {
bench(b, mpb.BarStyle(), true, 3)
}
func bench(b *testing.B, builder mpb.BarFillerBuilder, autoRefresh bool, n int) {
var wg sync.WaitGroup
p := mpb.New(
mpb.WithWidth(100),
mpb.WithOutput(io.Discard),
mpb.ContainerOptional(mpb.WithAutoRefresh(), autoRefresh),
)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for j := 0; j < n; j++ {
bar := p.New(total, builder)
switch j {
case n - 1:
complete(b, bar)
default:
wg.Add(1)
go func() {
complete(b, bar)
wg.Done()
}()
}
}
wg.Wait()
}
p.Wait()
}
func complete(b *testing.B, bar *mpb.Bar) {
for i := 0; i < total; i++ {
bar.Increment()
}
bar.Wait()
}
|