-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchcheck_integration_test.go
147 lines (129 loc) · 3.27 KB
/
benchcheck_integration_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//go:build integration
// +build integration
package benchcheck_test
import (
"strings"
"testing"
"github.com/madlambda/benchcheck"
"github.com/madlambda/spells/assert"
)
func TestStatModule(t *testing.T) {
type delta struct {
start float64
end float64
}
type diff struct {
name string
delta delta
}
type result struct {
metric string
diffs []diff
}
type testcase struct {
name string
module string
oldver string
newver string
want []result
}
if testing.Short() {
t.Skip("Skipping in short mode")
return
}
t.Parallel()
tcases := []testcase{
{
name: "stat benchcheck",
module: "github.com/madlambda/benchcheck",
oldver: "0f9165271a00b54163d3fc4c73d52a13c3747a75",
newver: "e90da7b50cf0e191004809e415c64319465286d7",
want: []result{
{
metric: "time/op",
diffs: []diff{
{
name: "Fake",
delta: delta{start: -85, end: -75},
},
},
},
},
},
{
name: "stat benchcheck reversed versions",
module: "github.com/madlambda/benchcheck",
oldver: "e90da7b50cf0e191004809e415c64319465286d7",
newver: "0f9165271a00b54163d3fc4c73d52a13c3747a75",
want: []result{
{
metric: "time/op",
diffs: []diff{
{
name: "Fake",
delta: delta{start: 395, end: 405},
},
},
},
},
},
{
name: "stat benchcheck same version",
module: "github.com/madlambda/benchcheck",
oldver: "e90da7b50cf0e191004809e415c64319465286d7",
newver: "e90da7b50cf0e191004809e415c64319465286d7",
want: []result{
{
metric: "time/op",
diffs: []diff{
{
name: "Fake",
delta: delta{start: -1, end: 1},
},
},
},
},
},
}
for _, tc := range tcases {
tcase := tc
t.Run(tcase.name, func(t *testing.T) {
t.Parallel()
got, err := benchcheck.StatModule(tcase.module, tcase.oldver, tcase.newver)
assertNoError(t, err)
// We can't check everything on the result since variance
// is introduced by changes on the environment (this is an e2e test).
// We can ensure results inside a reasonably broad delta + function names.
assert.EqualInts(t, len(tcase.want), len(got), "want %v != got %v", tcase, tcase.want, got)
for i, gotRes := range got {
wantRes := tcase.want[i]
t.Logf("got bench result: %v", gotRes)
assert.EqualStrings(t, wantRes.metric, gotRes.Metric)
for j, gotDiff := range gotRes.BenchDiffs {
wantDiff := wantRes.diffs[j]
gotName := stripProcCountFromBenchName(gotDiff.Name)
assert.EqualStrings(t, wantDiff.name, gotName)
if gotDiff.Delta < wantDiff.delta.start {
t.Fatalf(
"got delta %.2f < wanted delta start %.2f",
gotDiff.Delta, wantDiff.delta.start,
)
}
if gotDiff.Delta > wantDiff.delta.end {
t.Fatalf(
"got delta %.2f > wanted delta end %.2f",
gotDiff.Delta, wantDiff.delta.end,
)
}
}
}
})
}
}
func stripProcCountFromBenchName(name string) string {
// Benchmark names depend on count of CPUs:
// https://cs.opensource.google/go/go/+/refs/tags/go1.18.3:src/testing/benchmark.go;drc=47f806ce81aac555946144f112b9f8733e2ed871;l=495
// Here we remove this info so it is easier to test things independent of env.
lastIndex := strings.LastIndex(name, "-")
return name[:lastIndex]
}