-
Notifications
You must be signed in to change notification settings - Fork 444
/
benchmark.go
47 lines (39 loc) · 1.53 KB
/
benchmark.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
package helpers
import (
"fmt"
"os"
"strings"
"time"
"github.com/solo-io/gloo/test/testutils"
"github.com/onsi/gomega/types"
)
// Result represents the result of measuring a function's execution time.
type Result struct {
// Time spent in user mode
Utime time.Duration
// Time spent in kernel mode
Stime time.Duration
// Time spent in user mode + kernel mode
Total time.Duration
}
// BenchmarkConfig allows configuration for benchmarking tests to be reused for similar cases
// This struct can be factored out to an accessible location should additional benchmarking suites be added
type BenchmarkConfig struct {
Iterations int // the number of iterations to attempt for a particular entry
MaxDur time.Duration // the maximum time to spend on a particular entry even if not all iterations are complete
LocalMatchers []types.GomegaMatcher // matchers representing the assertions we wish to make for a particular entry when running locally
GhaMatchers []types.GomegaMatcher // matchers representing the assertions we wish to make for a particular entry when running in a GHA
}
func (bc *BenchmarkConfig) GetMatchers() []types.GomegaMatcher {
if os.Getenv(testutils.GithubAction) != "" {
return bc.GhaMatchers
}
return bc.LocalMatchers
}
func GenerateBenchmarkDesc(b *ScaledSnapshotBuilder, _ *BenchmarkConfig, labels ...string) string {
labelPrefix := ""
if len(labels) > 0 {
labelPrefix = fmt.Sprintf("(%s) ", strings.Join(labels, ", "))
}
return fmt.Sprintf("%s%s", labelPrefix, b.description())
}