-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscenarios_test.go
56 lines (47 loc) · 976 Bytes
/
scenarios_test.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package histogram_test
import (
"math"
"math/rand"
"sort"
)
var scenarios = []*Scenario{
{
Name: "uniform",
Next: func(r *rand.Rand) float64 { return r.Float64() * 200 },
},
{
Name: "lognorm",
Next: func(r *rand.Rand) float64 {
return 100 * math.Exp(r.NormFloat64()*0.9)
},
},
}
const numSeeds = 100_000
// ----------------------------------------------------------------------------
func init() {
rnd := rand.New(rand.NewSource(1))
for _, scn := range scenarios {
scn.init(rnd)
}
}
// Scenario is a benchmark scenario.
type Scenario struct {
Name string
Next func(*rand.Rand) float64
Data []float64
Candidates []Sketch
}
func (s *Scenario) init(r *rand.Rand) {
for _, new := range factories {
s.Candidates = append(s.Candidates, new())
}
s.Data = make([]float64, numSeeds)
for i := range s.Data {
x := s.Next(r)
s.Data[i] = x
for _, cnd := range s.Candidates {
cnd.Add(x)
}
}
sort.Float64s(s.Data)
}