minor: stress example with ewma decorators
Vladimir Bauer
1 year, 10 months ago
| 13 | 13 | ) |
| 14 | 14 | |
| 15 | 15 | const ( |
| 16 | totalBars = 32 | |
| 16 | totalBars = 42 | |
| 17 | 17 | ) |
| 18 | 18 | |
| 19 | 19 | var proftype = flag.String("prof", "", "profile type (cpu, mem)") |
| 37 | 37 | bar := p.AddBar(int64(total), |
| 38 | 38 | mpb.PrependDecorators( |
| 39 | 39 | decor.Name(name, decor.WCSyncWidthR), |
| 40 | decor.Elapsed(decor.ET_STYLE_GO, decor.WCSyncWidth), | |
| 40 | decor.OnComplete(decor.Percentage(decor.WCSyncWidth), "done"), | |
| 41 | 41 | ), |
| 42 | 42 | mpb.AppendDecorators( |
| 43 | decor.OnComplete(decor.Percentage(decor.WCSyncWidth), "done"), | |
| 43 | decor.OnComplete(decor.EwmaETA(decor.ET_STYLE_GO, 30, decor.WCSyncWidth), ""), | |
| 44 | decor.EwmaSpeed(decor.SizeB1024(0), "% .2f", 30, decor.WCSyncSpace), | |
| 44 | 45 | ), |
| 45 | 46 | ) |
| 46 | 47 | |
| 48 | 49 | defer wg.Done() |
| 49 | 50 | rng := rand.New(rand.NewSource(time.Now().UnixNano())) |
| 50 | 51 | max := 100 * time.Millisecond |
| 51 | for !bar.Completed() { | |
| 52 | for bar.IsRunning() { | |
| 53 | start := time.Now() | |
| 52 | 54 | time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10) |
| 53 | bar.Increment() | |
| 55 | bar.EwmaIncrement(time.Since(start)) | |
| 54 | 56 | } |
| 55 | 57 | }() |
| 56 | 58 | } |