README v5
Vladimir Bauer
6 years ago
| 24 | 24 | "math/rand" |
| 25 | 25 | "time" |
| 26 | 26 | |
| 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" | |
| 29 | 29 | ) |
| 30 | 30 | |
| 31 | 31 | func main() { |
| 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 taken time | |
| 55 | 57 | start := time.Now() |
| 56 | 58 | 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)) | |
| 59 | 62 | } |
| 60 | 63 | // wait for our bar to complete and flush |
| 61 | 64 | p.Wait() |
| 93 | 96 | rng := rand.New(rand.NewSource(time.Now().UnixNano())) |
| 94 | 97 | max := 100 * time.Millisecond |
| 95 | 98 | 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 | |
| 96 | 101 | start := time.Now() |
| 97 | 102 | 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)) | |
| 100 | 106 | } |
| 101 | 107 | }() |
| 102 | 108 | } |