Commit dda4591c authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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 <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarAustin Clements <austin@google.com>
parent 9ecf899b
......@@ -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)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment