Codebase list golang-github-vbauerster-mpb / c2416c5
README v5 Vladimir Bauer 6 years ago
1 changed file(s) with 12 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
2424 "math/rand"
2525 "time"
2626
27 "github.com/vbauerster/mpb/v4"
28 "github.com/vbauerster/mpb/v4/decor"
27 "github.com/vbauerster/mpb/v5"
28 "github.com/vbauerster/mpb/v5/decor"
2929 )
3030
3131 func main() {
5252 // simulating some work
5353 max := 100 * time.Millisecond
5454 for i := 0; i < total; i++ {
55 // start variable is solely for EWMA calculation
56 // EWMA's unit of measure is an iteration's taken time
5557 start := time.Now()
5658 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
57 // since ewma decorator is used, we need to pass time.Since(start)
58 bar.Increment(time.Since(start))
59 bar.Increment()
60 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
61 bar.DecoratorEwmaUpdate(time.Since(start))
5962 }
6063 // wait for our bar to complete and flush
6164 p.Wait()
9396 rng := rand.New(rand.NewSource(time.Now().UnixNano()))
9497 max := 100 * time.Millisecond
9598 for i := 0; i < total; i++ {
99 // start variable is solely for EWMA calculation
100 // EWMA's unit of measure is an iteration's taken time
96101 start := time.Now()
97102 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
98 // since ewma decorator is used, we need to pass time.Since(start)
99 bar.Increment(time.Since(start))
103 bar.Increment()
104 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
105 bar.DecoratorEwmaUpdate(time.Since(start))
100106 }
101107 }()
102108 }