Codebase list golang-github-vbauerster-mpb / d834feb
movingAverageSpeed: do not cache msg Vladimir Bauer 2 years ago
1 changed file(s) with 7 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
7979 producer func(float64) string
8080 average ewma.MovingAverage
8181 zDur time.Duration
82 msg string
8382 }
8483
8584 func (d *movingAverageSpeed) Decor(s Statistics) (string, int) {
86 if !s.Completed {
87 if v := d.average.Value(); v != 0 {
88 d.msg = d.producer(float64(1e9) / v)
89 } else {
90 d.msg = d.producer(v)
91 }
85 var str string
86 if v := d.average.Value(); v != 0 {
87 str = d.producer(float64(1e9) / v)
88 } else {
89 str = d.producer(0)
9290 }
93 return d.Format(d.msg)
91 return d.Format(str)
9492 }
9593
9694 func (d *movingAverageSpeed) EwmaUpdate(n int64, dur time.Duration) {
10199 if math.IsInf(durPerByte, 0) || math.IsNaN(durPerByte) {
102100 return
103101 }
102 d.zDur = 0
104103 d.average.Add(durPerByte)
105 d.zDur = 0
106104 }
107105 }
108106