Codebase list golang-github-vbauerster-mpb / 4664b45
dry bench test a bit Vladimir Bauer 4 years ago
1 changed file(s) with 12 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
2828 b.ResetTimer()
2929 for i := 0; i < b.N; i++ {
3030 for j := 0; j < n; j++ {
31 bar := p.AddBar(total)
3132 switch j {
3233 case n - 1:
33 bar := p.AddBar(total)
34 for c := 0; c < total; c++ {
35 bar.Increment()
36 }
37 if !bar.Completed() {
38 b.Fail()
39 }
34 complete(b, bar, total)
4035 default:
4136 wg.Add(1)
4237 go func() {
43 bar := p.AddBar(total)
44 for c := 0; c < total; c++ {
45 bar.Increment()
46 }
47 if !bar.Completed() {
48 b.Fail()
49 }
38 complete(b, bar, total)
5039 wg.Done()
5140 }()
5241 }
5544 }
5645 p.Wait()
5746 }
47
48 func complete(b *testing.B, bar *Bar, total int) {
49 for c := 0; c < total; c++ {
50 bar.Increment()
51 }
52 if !bar.Completed() {
53 b.Fail()
54 }
55 }