From dda4591c8cc0b57e76339f1f18a6f5670cee2aaa Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Fri, 6 Apr 2018 17:44:26 -0700 Subject: [PATCH] runtime: add BenchmarkScanStack 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 TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements --- src/runtime/gc_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/runtime/gc_test.go b/src/runtime/gc_test.go index d683d89fe4..4895a0e2ac 100644 --- a/src/runtime/gc_test.go +++ b/src/runtime/gc_test.go @@ -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) +} -- 2.50.0