-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
39 lines (34 loc) · 1.24 KB
/
Copy pathapp.go
File metadata and controls
39 lines (34 loc) · 1.24 KB
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
// Measuring performance is an important part of writing So programs.
// The `so/testing` package provides the tools we need to write
// benchmarks, and the `so bench` command runs them.
// By convention, benchmark code lives in the `bench` subdirectory of the
// package we are testing - that's where the `so bench` command looks for it.
//
// Do not name the file with benchmarks `main.go` - that file will be
// auto-generated when you run `so bench` and will contain the `main`
// function that runs the benchmarks.
//
// Do not use the `_test.go` suffix for benchmark files.
package app_bench
import (
"app"
"solod.dev/so/testing"
)
// A sink variable prevents the compiler from
// optimizing away the benchmarked code.
//
//so:volatile
var sink int
func BenchmarkIntMin(b *testing.B) {
// Any code that's required for the benchmark to run but should
// not be measured goes before this loop.
for b.Loop() {
// The benchmark runner will automatically execute this loop
// body many times to determine a reasonable estimate of the
// run-time of a single iteration.
sink = app.IntMin(1, 2)
// You can also use testing.Keep instead of the global sink
// variable to prevent the compiler from optimizing away the
// benchmarked code.
}
}