Codebase list golang-github-vbauerster-mpb / 43846d3
update ewma examples Vladimir Bauer 3 years ago
14 changed file(s) with 26 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
9595 // EWMA's unit of measure is an iteration's duration
9696 start := time.Now()
9797 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
98 bar.Increment()
99 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
100 bar.DecoratorEwmaUpdate(time.Since(start))
98 // we need to call EwmaIncrement to fulfill ewma decorator's contract
99 bar.EwmaIncrement(time.Since(start))
101100 }
102101 }()
103102 }
5151 // EWMA's unit of measure is an iteration's duration
5252 start := time.Now()
5353 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
54 bar.Increment()
55 // since EWMA based decorator is used, DecoratorEwmaUpdate should be called
56 bar.DecoratorEwmaUpdate(time.Since(start))
54 // we need to call EwmaIncrement to fulfill ewma decorator's contract
55 bar.EwmaIncrement(time.Since(start))
5756 }
5857 }()
5958 }
4343 // EWMA's unit of measure is an iteration's duration
4444 start := time.Now()
4545 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
46 bar.Increment()
47 // since EWMA based decorator is used, DecoratorEwmaUpdate should be called
48 bar.DecoratorEwmaUpdate(time.Since(start))
46 // we need to call EwmaIncrement to fulfill ewma decorator's contract
47 bar.EwmaIncrement(time.Since(start))
4948 }
5049 }()
5150 }
5757 // EWMA's unit of measure is an iteration's duration
5858 start := time.Now()
5959 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
60 bar.IncrInt64(rand.Int63n(5) + 1)
61 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
62 bar.DecoratorEwmaUpdate(time.Since(start))
60 // we need to call EwmaIncrement to fulfill ewma decorator's contract
61 bar.EwmaIncrInt64(rand.Int63n(5)+1, time.Since(start))
6362 }
6463 }
4848 // EWMA's unit of measure is an iteration's duration
4949 start := time.Now()
5050 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
51 bar.Increment()
52 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
53 bar.DecoratorEwmaUpdate(time.Since(start))
51 // we need to call EwmaIncrement to fulfill ewma decorator's contract
52 bar.EwmaIncrement(time.Since(start))
5453 }
5554 }()
5655 }
5252 // EWMA's unit of measure is an iteration's duration
5353 start := time.Now()
5454 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
55 bar.Increment()
56 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
57 bar.DecoratorEwmaUpdate(time.Since(start))
55 // we need to call EwmaIncrement to fulfill ewma decorator's contract
56 bar.EwmaIncrement(time.Since(start))
5857 }
5958 }()
6059 }
4343 // EWMA's unit of measure is an iteration's duration
4444 start := time.Now()
4545 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
46 bar.Increment()
47 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
48 bar.DecoratorEwmaUpdate(time.Since(start))
46 // we need to call EwmaIncrement to fulfill ewma decorator's contract
47 bar.EwmaIncrement(time.Since(start))
4948 }
5049 }()
5150 }
3434 // EWMA's unit of measure is an iteration's duration
3535 start := time.Now()
3636 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
37 bar.Increment()
38 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
39 bar.DecoratorEwmaUpdate(time.Since(start))
37 // we need to call EwmaIncrement to fulfill ewma decorator's contract
38 bar.EwmaIncrement(time.Since(start))
4039 }
4140 }
4241
4646 // EWMA's unit of measure is an iteration's duration
4747 start := time.Now()
4848 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
49 bar.Increment()
50 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
51 bar.DecoratorEwmaUpdate(time.Since(start))
49 // we need to call EwmaIncrement to fulfill ewma decorator's contract
50 bar.EwmaIncrement(time.Since(start))
5251 }
5352 log.Println(name, "done")
5453 }()
6161 // EWMA's unit of measure is an iteration's duration
6262 start := time.Now()
6363 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
64 bar.Increment()
65 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
66 bar.DecoratorEwmaUpdate(time.Since(start))
64 // we need to call EwmaIncrement to fulfill ewma decorator's contract
65 bar.EwmaIncrement(time.Since(start))
6766 }
6867 }()
6968 }
4343 // EWMA's unit of measure is an iteration's duration
4444 start := time.Now()
4545 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
46 bar.Increment()
47 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
48 bar.DecoratorEwmaUpdate(time.Since(start))
46 // we need to call EwmaIncrement to fulfill ewma decorator's contract
47 bar.EwmaIncrement(time.Since(start))
4948 }
5049 }()
5150 }
4444 // EWMA's unit of measure is an iteration's duration
4545 start := time.Now()
4646 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
47 bar.Increment()
48 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
49 bar.DecoratorEwmaUpdate(time.Since(start))
47 // we need to call EwmaIncrement to fulfill ewma decorator's contract
48 bar.EwmaIncrement(time.Since(start))
5049 }
5150 }()
5251 }
2424 decor.Name(name, decor.WC{W: len(name) + 1, C: decor.DidentRight}),
2525 // replace ETA decorator with "done" message, OnComplete event
2626 decor.OnComplete(
27 // ETA decorator with ewma age of 60, and width reservation of 4
28 decor.EwmaETA(decor.ET_STYLE_GO, 60, decor.WC{W: 4}), "done",
27 decor.AverageETA(decor.ET_STYLE_GO, decor.WC{W: 4}), "done",
2928 ),
3029 ),
3130 mpb.AppendDecorators(decor.Percentage()),
3332 // simulating some work
3433 max := 100 * time.Millisecond
3534 for i := 0; i < total; i++ {
36 // start variable is solely for EWMA calculation
37 // EWMA's unit of measure is an iteration's duration
38 start := time.Now()
3935 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
4036 bar.Increment()
41 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
42 bar.DecoratorEwmaUpdate(time.Since(start))
4337 }
4438 // wait for our bar to complete and flush
4539 p.Wait()
156156 }
157157 }
158158 time.Sleep(randomDuration(100 * time.Millisecond))
159 bar.IncrInt64(rand.Int63n(5) + 1)
160 bar.DecoratorEwmaUpdate(time.Since(start))
159 bar.EwmaIncrInt64(rand.Int63n(5)+1, time.Since(start))
161160 }
162161 }()
163162 }