Skip to content

Commit

Permalink
movingAverageSpeed: do not cache msg
Browse files Browse the repository at this point in the history
  • Loading branch information
vbauerster committed Dec 26, 2023
1 parent da84b21 commit d834feb
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions decor/speed.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,16 @@ type movingAverageSpeed struct {
producer func(float64) string
average ewma.MovingAverage
zDur time.Duration
msg string
}

func (d *movingAverageSpeed) Decor(s Statistics) (string, int) {
if !s.Completed {
if v := d.average.Value(); v != 0 {
d.msg = d.producer(float64(1e9) / v)
} else {
d.msg = d.producer(v)
}
var str string
if v := d.average.Value(); v != 0 {
str = d.producer(float64(1e9) / v)
} else {
str = d.producer(0)
}
return d.Format(d.msg)
return d.Format(str)
}

func (d *movingAverageSpeed) EwmaUpdate(n int64, dur time.Duration) {
Expand All @@ -102,8 +100,8 @@ func (d *movingAverageSpeed) EwmaUpdate(n int64, dur time.Duration) {
if math.IsInf(durPerByte, 0) || math.IsNaN(durPerByte) {
return
}
d.average.Add(durPerByte)
d.zDur = 0
d.average.Add(durPerByte)
}
}

Expand Down

0 comments on commit d834feb

Please sign in to comment.