-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstat_test.go
More file actions
41 lines (32 loc) · 921 Bytes
/
stat_test.go
File metadata and controls
41 lines (32 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright © 2020-2022. All rights reserved.
// Author: Ilya Stroy.
// Contacts: iyuryevich@pm.me, https://github.com/qioalice
// License: https://opensource.org/licenses/MIT
package ekamath_test
import (
"strconv"
"testing"
"github.com/qioalice/ekago/v3/ekamath"
)
func BenchmarkStat(b *testing.B) {
var statWeight = []int{100, 1_000, 10_000, 100_000}
var genBench = func(n int, s ekamath.Stat[int]) func(*testing.B) {
return func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
s.Clear()
for j := 0; j < n; j++ {
s.Count(j)
}
_ = s.Avg()
}
}
}
var sc = ekamath.NewStatCumulative[int]()
var si = ekamath.NewStatIterative[int]()
for i, n := 0, len(statWeight); i < n; i++ {
var weightStr = strconv.Itoa(statWeight[i])
b.Run("Cumulative"+"-"+weightStr, genBench(statWeight[i], sc))
b.Run("Iterative"+"-"+weightStr, genBench(statWeight[i], si))
}
}