mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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: Austin Clements <austin@google.com>
This commit is contained in:
parent
9ecf899b29
commit
dda4591c8c
1 changed files with 32 additions and 0 deletions
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -643,3 +644,34 @@ func BenchmarkBulkWriteBarrier(b *testing.B) {
|
||||||
|
|
||||||
runtime.KeepAlive(ptrs)
|
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)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue