single bar examlpe use AverageETA
Vladimir Bauer
6 years ago
| 44 | 44 |
// replace ETA decorator with "done" message, OnComplete event
|
| 45 | 45 |
decor.OnComplete(
|
| 46 | 46 |
// ETA decorator with ewma age of 60, and width reservation of 4
|
| 47 | |
decor.EwmaETA(decor.ET_STYLE_GO, 60, decor.WC{W: 4}), "done",
|
|
47 |
decor.AverageETA(decor.ET_STYLE_GO, decor.WC{W: 4}), "done",
|
| 48 | 48 |
),
|
| 49 | 49 |
),
|
| 50 | 50 |
mpb.AppendDecorators(decor.Percentage()),
|
|
| 52 | 52 |
// simulating some work
|
| 53 | 53 |
max := 100 * time.Millisecond
|
| 54 | 54 |
for i := 0; i < total; i++ {
|
| 55 | |
// start variable is solely for EWMA calculation
|
| 56 | |
// EWMA's unit of measure is an iteration's duration
|
| 57 | |
start := time.Now()
|
| 58 | 55 |
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
|
| 59 | 56 |
bar.Increment()
|
| 60 | |
// we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
|
| 61 | |
bar.DecoratorEwmaUpdate(time.Since(start))
|
| 62 | 57 |
}
|
| 63 | 58 |
// wait for our bar to complete and flush
|
| 64 | 59 |
p.Wait()
|
| 22 | 22 |
decor.Name(name, decor.WC{W: len(name) + 1, C: decor.DidentRight}),
|
| 23 | 23 |
// replace ETA decorator with "done" message, OnComplete event
|
| 24 | 24 |
decor.OnComplete(
|
| 25 | |
// ETA decorator with ewma age of 60, and width reservation of 4
|
| 26 | |
decor.EwmaETA(decor.ET_STYLE_GO, 60, decor.WC{W: 4}), "done",
|
|
25 |
decor.AverageETA(decor.ET_STYLE_GO, decor.WC{W: 4}), "done",
|
| 27 | 26 |
),
|
| 28 | 27 |
),
|
| 29 | 28 |
mpb.AppendDecorators(decor.Percentage()),
|
|
| 31 | 30 |
// simulating some work
|
| 32 | 31 |
max := 100 * time.Millisecond
|
| 33 | 32 |
for i := 0; i < total; i++ {
|
| 34 | |
// start variable is solely for EWMA calculation
|
| 35 | |
// EWMA's unit of measure is an iteration's duration
|
| 36 | |
start := time.Now()
|
| 37 | 33 |
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
|
| 38 | 34 |
bar.Increment()
|
| 39 | |
// we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
|
| 40 | |
bar.DecoratorEwmaUpdate(time.Since(start))
|
| 41 | 35 |
}
|
| 42 | 36 |
// wait for our bar to complete and flush
|
| 43 | 37 |
p.Wait()
|