From 38d4d3c66a2aaaa7e4a73d197bbe425116b8ef49 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Fri, 1 Mar 2013 01:10:34 +0200 Subject: [PATCH] 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 --- src/pkg/runtime/proc_test.go | 37 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/pkg/runtime/proc_test.go b/src/pkg/runtime/proc_test.go index b2fa4c9c26..21fb9c2f7f 100644 --- a/src/pkg/runtime/proc_test.go +++ b/src/pkg/runtime/proc_test.go @@ -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 } -- 2.48.1