]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add BenchmarkScanStack
authorJosh Bleecher Snyder <josharian@gmail.com>
Sat, 7 Apr 2018 00:44:26 +0000 (17:44 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 1 May 2018 13:33:01 +0000 (13:33 +0000)
There are many possible stack scanning benchmarks,
but this one is at least a start.

cpuprofiling shows about 75% of CPU in func scanstack.

Change-Id: I906b0493966f2165c1920636c4e057d16d6447e0
Reviewed-on: https://go-review.googlesource.com/105535
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/gc_test.go

index d683d89fe405d92b527a425d09783534bcc6171d..4895a0e2ac90b789bc5e604fcce332ed8eee468d 100644 (file)
@@ -10,6 +10,7 @@ import (
        "reflect"
        "runtime"
        "runtime/debug"
+       "sync"
        "sync/atomic"
        "testing"
        "time"
@@ -643,3 +644,34 @@ func BenchmarkBulkWriteBarrier(b *testing.B) {
 
        runtime.KeepAlive(ptrs)
 }
+
+func BenchmarkScanStackNoLocals(b *testing.B) {
+       var ready sync.WaitGroup
+       teardown := make(chan bool)
+       for j := 0; j < 10; j++ {
+               ready.Add(1)
+               go func() {
+                       x := 100000
+                       countpwg(&x, &ready, teardown)
+               }()
+       }
+       ready.Wait()
+       b.ResetTimer()
+       for i := 0; i < b.N; i++ {
+               b.StartTimer()
+               runtime.GC()
+               runtime.GC()
+               b.StopTimer()
+       }
+       close(teardown)
+}
+
+func countpwg(n *int, ready *sync.WaitGroup, teardown chan bool) {
+       if *n == 0 {
+               ready.Done()
+               <-teardown
+               return
+       }
+       *n--
+       countpwg(n, ready, teardown)
+}