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>
"reflect"
"runtime"
"runtime/debug"
+ "sync"
"sync/atomic"
"testing"
"time"
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)
+}