]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: refactor Syscall benchmark
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 28 Feb 2013 23:10:34 +0000 (01:10 +0200)
committerDmitriy Vyukov <dvyukov@google.com>
Thu, 28 Feb 2013 23:10:34 +0000 (01:10 +0200)
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

index b2fa4c9c263239cff393160f253f3e896b00bab5..21fb9c2f7f75c1a849027080440e9740d0068991 100644 (file)
@@ -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
                                        }