Files
math/continuous_averager_benchmark_test.go
T
Zach Kelling fd27f2ecb0 Reorganize math package into subpackages
- Create math/big for big.Int utilities (HexOrDecimal256, U256, parsing)
- Create math/safe for overflow-safe arithmetic (SafeAdd, SafeMul, etc.)
- Move averager files to root package level
- Add re-exports in root package for backwards compatibility
- Update README with new package structure documentation
- Remove old math/meter directory (consolidated elsewhere)
- Remove redundant math/ subdirectory structure
2026-01-03 18:22:33 -08:00

36 lines
733 B
Go

// Copyright (C) 2019-2024, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package math
import (
"fmt"
"testing"
"time"
)
func BenchmarkAveragers(b *testing.B) {
periods := []time.Duration{
time.Millisecond,
time.Duration(0),
-time.Millisecond,
}
for _, period := range periods {
name := fmt.Sprintf("period=%s", period)
b.Run(name, func(b *testing.B) {
a := NewAverager(0, time.Second, time.Now())
AveragerBenchmark(b, a, period)
})
}
}
func AveragerBenchmark(b *testing.B, a Averager, period time.Duration) {
currentTime := time.Now()
b.ResetTimer()
for i := 0; i < b.N; i++ {
currentTime = currentTime.Add(period)
a.Observe(float64(i), currentTime)
}
}