-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunc_test.go
50 lines (43 loc) · 855 Bytes
/
func_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
package benchmarks
import (
"testing"
)
func simple_func(output *int, value bool) {
*output++
if value { // Never run.
simple_func(output, value)
}
}
//go:nosplit
func nosplit_func(output *int, value bool) {
*output++
if value { // Never run.
simple_func(output, value)
}
}
func baseline(output *int, value bool) {
*output++
if value {
// Never run. We want the cost of the comparison, but don't
// make this recursive because we still want it to be inlined.
*output++
}
}
func BenchmarkBaselineFunc(b *testing.B) {
var value int
for i := 0; i < b.N; i++ {
baseline(&value, false)
}
}
func BenchmarkNormalFunc(b *testing.B) {
var value int
for i := 0; i < b.N; i++ {
simple_func(&value, false)
}
}
func BenchmarkNosplitFunc(b *testing.B) {
var value int
for i := 0; i < b.N; i++ {
nosplit_func(&value, false)
}
}