Source file
src/runtime/norace_test.go
1
2
3
4
5
6
7
8 package runtime_test
9
10 import (
11 "runtime"
12 "testing"
13 )
14
15
16 func BenchmarkSyscall(b *testing.B) {
17 benchmarkSyscall(b, 0, 1)
18 }
19
20 func BenchmarkSyscallWork(b *testing.B) {
21 benchmarkSyscall(b, 100, 1)
22 }
23
24 func BenchmarkSyscallExcess(b *testing.B) {
25 benchmarkSyscall(b, 0, 4)
26 }
27
28 func BenchmarkSyscallExcessWork(b *testing.B) {
29 benchmarkSyscall(b, 100, 4)
30 }
31
32 func benchmarkSyscall(b *testing.B, work, excess int) {
33 b.SetParallelism(excess)
34 b.RunParallel(func(pb *testing.PB) {
35 foo := 42
36 for pb.Next() {
37 runtime.Entersyscall()
38 for i := 0; i < work; i++ {
39 foo *= 2
40 foo /= 2
41 }
42 runtime.Exitsyscall()
43 }
44 _ = foo
45 })
46 }
47
View as plain text