Commit 38d4d3c6 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime: refactor Syscall benchmark

And add a benchmark where #goroutines>GOMAXPROCS,
because it's the most interesting case.
Current results on darwin/amd64, Intel Core 2 Duo 2.13 GHz, 2 cores:
BenchmarkSyscall	100000000	        56.0 ns/op
BenchmarkSyscall-2	50000000	        57.2 ns/op
BenchmarkSyscallWork	10000000	       635 ns/op
BenchmarkSyscallWork-2	10000000	       315 ns/op
BenchmarkSyscallExcess	 1000000	      2698 ns/op
BenchmarkSyscallExcess-2	 5000000	      1192 ns/op
BenchmarkSyscallExcessWork	 1000000	      2832 ns/op
BenchmarkSyscallExcessWork-2	 2000000	      1966 ns/op

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7415044
parent 72b09bd7
......@@ -152,31 +152,24 @@ func BenchmarkStackGrowthDeep(b *testing.B) {
}
func BenchmarkSyscall(b *testing.B) {
const CallsPerSched = 1000
procs := runtime.GOMAXPROCS(-1)
N := int32(b.N / CallsPerSched)
c := make(chan bool, procs)
for p := 0; p < procs; p++ {
go func() {
for atomic.AddInt32(&N, -1) >= 0 {
runtime.Gosched()
for g := 0; g < CallsPerSched; g++ {
runtime.Entersyscall()
runtime.Exitsyscall()
}
}
c <- true
}()
}
for p := 0; p < procs; p++ {
<-c
}
benchmarkSyscall(b, 0, 1)
}
func BenchmarkSyscallWork(b *testing.B) {
benchmarkSyscall(b, 100, 1)
}
func BenchmarkSyscallExcess(b *testing.B) {
benchmarkSyscall(b, 0, 4)
}
func BenchmarkSyscallExcessWork(b *testing.B) {
benchmarkSyscall(b, 100, 4)
}
func benchmarkSyscall(b *testing.B, work, excess int) {
const CallsPerSched = 1000
const LocalWork = 100
procs := runtime.GOMAXPROCS(-1)
procs := runtime.GOMAXPROCS(-1) * excess
N := int32(b.N / CallsPerSched)
c := make(chan bool, procs)
for p := 0; p < procs; p++ {
......@@ -186,7 +179,7 @@ func BenchmarkSyscallWork(b *testing.B) {
runtime.Gosched()
for g := 0; g < CallsPerSched; g++ {
runtime.Entersyscall()
for i := 0; i < LocalWork; i++ {
for i := 0; i < work; i++ {
foo *= 2
foo /= 2
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment