forked from operator-framework/operator-lifecycle-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_test.go
83 lines (76 loc) · 1.49 KB
/
bench_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package solver
import (
"context"
"math/rand"
"strconv"
"testing"
)
var BenchmarkInput = func() []Variable {
const (
length = 256
seed = 9
pMandatory = .1
pDependency = .15
nDependency = 6
pConflict = .05
nConflict = 3
)
id := func(i int) Identifier {
return Identifier(strconv.Itoa(i))
}
variable := func(i int) TestVariable {
var c []Constraint
if rand.Float64() < pMandatory {
c = append(c, Mandatory())
}
if rand.Float64() < pDependency {
n := rand.Intn(nDependency-1) + 1
var d []Identifier
for x := 0; x < n; x++ {
y := i
for y == i {
y = rand.Intn(length)
}
d = append(d, id(y))
}
c = append(c, Dependency(d...))
}
if rand.Float64() < pConflict {
n := rand.Intn(nConflict-1) + 1
for x := 0; x < n; x++ {
y := i
for y == i {
y = rand.Intn(length)
}
c = append(c, Conflict(id(y)))
}
}
return TestVariable{
identifier: id(i),
constraints: c,
}
}
rand.Seed(seed)
result := make([]Variable, length)
for i := range result {
result[i] = variable(i)
}
return result
}()
func BenchmarkSolve(b *testing.B) {
for i := 0; i < b.N; i++ {
s, err := New(WithInput(BenchmarkInput))
if err != nil {
b.Fatalf("failed to initialize solver: %s", err)
}
s.Solve(context.Background())
}
}
func BenchmarkNewInput(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := New(WithInput(BenchmarkInput))
if err != nil {
b.Fatalf("failed to initialize solver: %s", err)
}
}
}