-
Notifications
You must be signed in to change notification settings - Fork 0
/
change.go
56 lines (45 loc) · 1.09 KB
/
change.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 change implements change detection in benchmark timeseries.
package change
import (
"github.com/mmcloughlin/goperf/pkg/units"
)
type Change struct {
CommitIndex int
EffectSize float64
Pre Stats
Post Stats
}
func (c *Change) Delta() float64 {
return c.Post.Mean - c.Pre.Mean
}
func (c *Change) Percent() float64 {
return 100 * c.Delta() / c.Pre.Mean
}
// Type of a change: improvement or regression.
type Type int
// Supported change types.
const (
TypeUnknown Type = iota
TypeUnchanged
TypeImprovement
TypeRegression
)
//go:generate enumer -type Type -output type_enum.go -trimprefix Type -transform snake
// Classify a change from pre to post in the given unit.
func Classify(pre, post float64, unit string) Type {
if post == pre {
return TypeUnchanged
}
d := units.ImprovementDirectionForUnit(unit)
if d != units.ImprovementDirectionSmaller && d != units.ImprovementDirectionLarger {
return TypeUnknown
}
delta := post - pre
if d == units.ImprovementDirectionSmaller {
delta = -delta
}
if delta > 0 {
return TypeImprovement
}
return TypeRegression
}