File: barbench_test.go

package info (click to toggle)
golang-github-vbauerster-mpb 8.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,044 kB
  • sloc: sh: 7; makefile: 3
file content (89 lines) | stat: -rw-r--r-- 1,753 bytes parent folder | download
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
package mpb_test

import (
	"io"
	"testing"

	"github.com/vbauerster/mpb/v8"
)

const total = 1000

func BenchmarkNopStyleB1(b *testing.B) {
	bench(b, mpb.NopStyle(), false, 1)
}

func BenchmarkNopStyleWithAutoRefreshB1(b *testing.B) {
	bench(b, mpb.NopStyle(), true, 1)
}

func BenchmarkNopStylesB2(b *testing.B) {
	bench(b, mpb.NopStyle(), false, 2)
}

func BenchmarkNopStylesWithAutoRefreshB2(b *testing.B) {
	bench(b, mpb.NopStyle(), true, 2)
}

func BenchmarkNopStylesB3(b *testing.B) {
	bench(b, mpb.NopStyle(), false, 3)
}

func BenchmarkNopStylesWithAutoRefreshB3(b *testing.B) {
	bench(b, mpb.NopStyle(), true, 3)
}

func BenchmarkBarStyleB1(b *testing.B) {
	bench(b, mpb.BarStyle(), false, 1)
}

func BenchmarkBarStyleWithAutoRefreshB1(b *testing.B) {
	bench(b, mpb.BarStyle(), true, 1)
}

func BenchmarkBarStylesB2(b *testing.B) {
	bench(b, mpb.BarStyle(), false, 2)
}

func BenchmarkBarStylesWithAutoRefreshB2(b *testing.B) {
	bench(b, mpb.BarStyle(), true, 2)
}

func BenchmarkBarStylesB3(b *testing.B) {
	bench(b, mpb.BarStyle(), false, 3)
}

func BenchmarkBarStylesWithAutoRefreshB3(b *testing.B) {
	bench(b, mpb.BarStyle(), true, 3)
}

func bench(b *testing.B, builder mpb.BarFillerBuilder, autoRefresh bool, n int) {
	p := mpb.New(
		mpb.WithWidth(100),
		mpb.WithOutput(io.Discard),
		mpb.ContainerOptional(mpb.WithAutoRefresh(), autoRefresh),
	)
	defer p.Wait()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		var bars []*mpb.Bar
		for j := 0; j < n; j++ {
			bars = append(bars, p.New(total, builder))
			switch j {
			case n - 1:
				complete(bars[j])
			default:
				go complete(bars[j])
			}
		}
		for _, bar := range bars {
			bar.Wait()
		}
	}
}

func complete(bar *mpb.Bar) {
	for i := 0; i < total; i++ {
		bar.Increment()
	}
}