refactor benchmark
Vladimir Bauer
8 years ago
| 4 | 4 | "testing" |
| 5 | 5 | ) |
| 6 | 6 | |
| 7 | func benchmarkSingleBar(total int) { | |
| 8 | p := New(WithOutput(ioutil.Discard)) | |
| 9 | bar := p.AddBar(int64(total)) | |
| 10 | for i := 0; i < total; i++ { | |
| 11 | bar.Increment() | |
| 12 | } | |
| 13 | p.Wait() | |
| 14 | } | |
| 15 | ||
| 16 | func BenchmarkSingleBar100(b *testing.B) { | |
| 17 | for i := 0; i < b.N; i++ { | |
| 18 | benchmarkSingleBar(100) | |
| 19 | } | |
| 20 | } | |
| 21 | ||
| 22 | func BenchmarkSingleBar1000(b *testing.B) { | |
| 23 | for i := 0; i < b.N; i++ { | |
| 24 | benchmarkSingleBar(1000) | |
| 25 | } | |
| 26 | } | |
| 27 | ||
| 28 | func BenchmarkSingleBar10000(b *testing.B) { | |
| 29 | for i := 0; i < b.N; i++ { | |
| 30 | benchmarkSingleBar(10000) | |
| 31 | } | |
| 32 | } | |
| 33 | ||
| 34 | 7 | func BenchmarkIncrSingleBar(b *testing.B) { |
| 35 | 8 | p := New(WithOutput(ioutil.Discard)) |
| 36 | 9 | bar := p.AddBar(int64(b.N)) |
| 37 | 10 | for i := 0; i < b.N; i++ { |
| 38 | 11 | bar.Increment() |
| 39 | 12 | } |
| 40 | p.Wait() | |
| 41 | 13 | } |
| 14 | ||
| 15 | func BenchmarkIncrSingleBarStartBlock(b *testing.B) { | |
| 16 | p := New(WithOutput(ioutil.Discard)) | |
| 17 | bar := p.AddBar(int64(b.N)) | |
| 18 | for i := 0; i < b.N; i++ { | |
| 19 | bar.StartBlock() | |
| 20 | bar.Increment() | |
| 21 | } | |
| 22 | } | |
| 23 | ||
| 24 | func BenchmarkIncrSingleBarWhileIsNotCompleted(b *testing.B) { | |
| 25 | p := New(WithOutput(ioutil.Discard)) | |
| 26 | bar := p.AddBar(int64(b.N)) | |
| 27 | for !bar.Completed() { | |
| 28 | bar.Increment() | |
| 29 | } | |
| 30 | } |