diff --git a/barbench_test.go b/barbench_test.go index 7926afa..4b440d3 100644 --- a/barbench_test.go +++ b/barbench_test.go @@ -29,25 +29,14 @@ b.ResetTimer() for i := 0; i < b.N; i++ { for j := 0; j < n; j++ { + bar := p.AddBar(total) switch j { case n - 1: - bar := p.AddBar(total) - for c := 0; c < total; c++ { - bar.Increment() - } - if !bar.Completed() { - b.Fail() - } + complete(b, bar, total) default: wg.Add(1) go func() { - bar := p.AddBar(total) - for c := 0; c < total; c++ { - bar.Increment() - } - if !bar.Completed() { - b.Fail() - } + complete(b, bar, total) wg.Done() }() } @@ -56,3 +45,12 @@ } p.Wait() } + +func complete(b *testing.B, bar *Bar, total int) { + for c := 0; c < total; c++ { + bar.Increment() + } + if !bar.Completed() { + b.Fail() + } +}