diff --git a/decor/speed.go b/decor/speed.go index 6ecdd58..f88481e 100644 --- a/decor/speed.go +++ b/decor/speed.go @@ -83,8 +83,13 @@ return d.FormatMsg(d.msg) } - d.msg = d.producer(d.average.Value()) + var speed float64 + if v := math.Round(d.average.Value()); v != 0 { + current := float64(st.Current) + speed = current / (current * time.Duration(v).Seconds()) + } + d.msg = d.producer(speed) return d.FormatMsg(d.msg) } @@ -93,11 +98,11 @@ for _, wd := range wdd { workDuration = wd } - speed := float64(n) / workDuration.Seconds() / 1000 - if math.IsInf(speed, 0) || math.IsNaN(speed) { + durPerByte := float64(workDuration) / float64(n) + if math.IsInf(durPerByte, 0) || math.IsNaN(durPerByte) { return } - d.average.Add(speed) + d.average.Add(durPerByte) } func (d *movingAverageSpeed) OnCompleteMessage(msg string) {