dry bench test a bit
Vladimir Bauer
4 years ago
| 28 | 28 | b.ResetTimer() |
| 29 | 29 | for i := 0; i < b.N; i++ { |
| 30 | 30 | for j := 0; j < n; j++ { |
| 31 | bar := p.AddBar(total) | |
| 31 | 32 | switch j { |
| 32 | 33 | 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) | |
| 40 | 35 | default: |
| 41 | 36 | wg.Add(1) |
| 42 | 37 | 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) | |
| 50 | 39 | wg.Done() |
| 51 | 40 | }() |
| 52 | 41 | } |
| 55 | 44 | } |
| 56 | 45 | p.Wait() |
| 57 | 46 | } |
| 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 | } | |