update ewma examples
Vladimir Bauer
3 years ago
| 95 | 95 |
// EWMA's unit of measure is an iteration's duration
|
| 96 | 96 |
start := time.Now()
|
| 97 | 97 |
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))
|
| 101 | 100 |
}
|
| 102 | 101 |
}()
|
| 103 | 102 |
}
|
| 51 | 51 |
// EWMA's unit of measure is an iteration's duration
|
| 52 | 52 |
start := time.Now()
|
| 53 | 53 |
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))
|
| 57 | 56 |
}
|
| 58 | 57 |
}()
|
| 59 | 58 |
}
|
| 43 | 43 |
// EWMA's unit of measure is an iteration's duration
|
| 44 | 44 |
start := time.Now()
|
| 45 | 45 |
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))
|
| 49 | 48 |
}
|
| 50 | 49 |
}()
|
| 51 | 50 |
}
|
| 57 | 57 |
// EWMA's unit of measure is an iteration's duration
|
| 58 | 58 |
start := time.Now()
|
| 59 | 59 |
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))
|
| 63 | 62 |
}
|
| 64 | 63 |
}
|
| 48 | 48 |
// EWMA's unit of measure is an iteration's duration
|
| 49 | 49 |
start := time.Now()
|
| 50 | 50 |
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))
|
| 54 | 53 |
}
|
| 55 | 54 |
}()
|
| 56 | 55 |
}
|
| 52 | 52 |
// EWMA's unit of measure is an iteration's duration
|
| 53 | 53 |
start := time.Now()
|
| 54 | 54 |
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))
|
| 58 | 57 |
}
|
| 59 | 58 |
}()
|
| 60 | 59 |
}
|
| 43 | 43 |
// EWMA's unit of measure is an iteration's duration
|
| 44 | 44 |
start := time.Now()
|
| 45 | 45 |
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))
|
| 49 | 48 |
}
|
| 50 | 49 |
}()
|
| 51 | 50 |
}
|
| 34 | 34 |
// EWMA's unit of measure is an iteration's duration
|
| 35 | 35 |
start := time.Now()
|
| 36 | 36 |
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))
|
| 40 | 39 |
}
|
| 41 | 40 |
}
|
| 42 | 41 |
|
| 46 | 46 |
// EWMA's unit of measure is an iteration's duration
|
| 47 | 47 |
start := time.Now()
|
| 48 | 48 |
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))
|
| 52 | 51 |
}
|
| 53 | 52 |
log.Println(name, "done")
|
| 54 | 53 |
}()
|
| 61 | 61 |
// EWMA's unit of measure is an iteration's duration
|
| 62 | 62 |
start := time.Now()
|
| 63 | 63 |
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))
|
| 67 | 66 |
}
|
| 68 | 67 |
}()
|
| 69 | 68 |
}
|
| 43 | 43 |
// EWMA's unit of measure is an iteration's duration
|
| 44 | 44 |
start := time.Now()
|
| 45 | 45 |
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))
|
| 49 | 48 |
}
|
| 50 | 49 |
}()
|
| 51 | 50 |
}
|
| 44 | 44 |
// EWMA's unit of measure is an iteration's duration
|
| 45 | 45 |
start := time.Now()
|
| 46 | 46 |
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))
|
| 50 | 49 |
}
|
| 51 | 50 |
}()
|
| 52 | 51 |
}
|
| 24 | 24 |
decor.Name(name, decor.WC{W: len(name) + 1, C: decor.DidentRight}),
|
| 25 | 25 |
// replace ETA decorator with "done" message, OnComplete event
|
| 26 | 26 |
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",
|
| 29 | 28 |
),
|
| 30 | 29 |
),
|
| 31 | 30 |
mpb.AppendDecorators(decor.Percentage()),
|
|
| 33 | 32 |
// simulating some work
|
| 34 | 33 |
max := 100 * time.Millisecond
|
| 35 | 34 |
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()
|
| 39 | 35 |
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
|
| 40 | 36 |
bar.Increment()
|
| 41 | |
// we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
|
| 42 | |
bar.DecoratorEwmaUpdate(time.Since(start))
|
| 43 | 37 |
}
|
| 44 | 38 |
// wait for our bar to complete and flush
|
| 45 | 39 |
p.Wait()
|
| 156 | 156 |
}
|
| 157 | 157 |
}
|
| 158 | 158 |
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))
|
| 161 | 160 |
}
|
| 162 | 161 |
}()
|
| 163 | 162 |
}
|