]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add goroutine creation benchmark
authorDmitriy Vyukov <dvyukov@google.com>
Wed, 27 Jun 2012 17:57:49 +0000 (21:57 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Wed, 27 Jun 2012 17:57:49 +0000 (21:57 +0400)
Current results on 2 core darwin/amd64:
BenchmarkGoroutineChain 351 ns/op
BenchmarkGoroutineChain-2 3840 ns/op
BenchmarkGoroutineChain-4 4040 ns/op
BenchmarkConcGoroutineChain 350 ns/op
BenchmarkConcGoroutineChain-2 875 ns/op
BenchmarkConcGoroutineChain-4 2027 ns/op

R=r, rsc
CC=golang-dev
https://golang.org/cl/6332054

src/pkg/runtime/proc_test.go

index 32111080a5465b8f0eeb6999af5b0a4c7b5e6eda..1d51c5271e37dd27589903a94da293e374f40711 100644 (file)
@@ -123,3 +123,29 @@ func BenchmarkSyscallWork(b *testing.B) {
                <-c
        }
 }
+
+func BenchmarkCreateGoroutines(b *testing.B) {
+       benchmarkCreateGoroutines(b, 1)
+}
+
+func BenchmarkCreateGoroutinesParallel(b *testing.B) {
+       benchmarkCreateGoroutines(b, runtime.GOMAXPROCS(-1))
+}
+
+func benchmarkCreateGoroutines(b *testing.B, procs int) {
+       c := make(chan bool)
+       var f func(n int)
+       f = func(n int) {
+               if n == 0 {
+                       c <- true
+                       return
+               }
+               go f(n - 1)
+       }
+       for i := 0; i < procs; i++ {
+               go f(b.N / procs)
+       }
+       for i := 0; i < procs; i++ {
+               <-c
+       }
+}