example update
Vladimir Bauer
6 years ago
| 61 | 61 | rng := rand.New(rand.NewSource(time.Now().UnixNano())) |
| 62 | 62 | max := 100 * time.Millisecond |
| 63 | 63 | for i := 0; i < total; i++ { |
| 64 | // start variable is solely for EWMA calculation | |
| 65 | // EWMA's unit of measure is an iteration's taken time | |
| 64 | 66 | start := time.Now() |
| 65 | 67 | time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) |
| 66 | // since ewma decorator is used, we need to pass time.Since(start) | |
| 67 | bar.Increment(time.Since(start)) | |
| 68 | bar.Increment() | |
| 69 | // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract | |
| 70 | bar.DecoratorEwmaUpdate(time.Since(start)) | |
| 68 | 71 | } |
| 69 | 72 | }() |
| 70 | 73 | } |