movingAverageSpeed: do not cache msg
Vladimir Bauer
2 years ago
| 79 | 79 | producer func(float64) string |
| 80 | 80 | average ewma.MovingAverage |
| 81 | 81 | zDur time.Duration |
| 82 | msg string | |
| 83 | 82 | } |
| 84 | 83 | |
| 85 | 84 | 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) | |
| 92 | 90 | } |
| 93 | return d.Format(d.msg) | |
| 91 | return d.Format(str) | |
| 94 | 92 | } |
| 95 | 93 | |
| 96 | 94 | func (d *movingAverageSpeed) EwmaUpdate(n int64, dur time.Duration) { |
| 101 | 99 | if math.IsInf(durPerByte, 0) || math.IsNaN(durPerByte) { |
| 102 | 100 | return |
| 103 | 101 | } |
| 102 | d.zDur = 0 | |
| 104 | 103 | d.average.Add(durPerByte) |
| 105 | d.zDur = 0 | |
| 106 | 104 | } |
| 107 | 105 | } |
| 108 | 106 | |