aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/stack_test.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2021-10-05 09:40:15 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2021-10-05 20:35:41 +0000
commit75773b0e7b4dac6b779e869a13096a7b7f0be5bb (patch)
tree43c8b76abf85629771ec69c8a1af71215483b127 /src/runtime/stack_test.go
parent0b4d4998d57936cf8bb2566f5f3e36eb70892ca4 (diff)
downloadgo-75773b0e7b4dac6b779e869a13096a7b7f0be5bb.tar.xz
runtime: add BenchmarkStackCopyWithStkobj
For benchmarking and improving recent stkobj-related changes. Co-Authored-By: Cherry Mui <cherryyz@google.com> Change-Id: I34c8b1a09e4cf98547460882b0d3908158269f57 Reviewed-on: https://go-review.googlesource.com/c/go/+/354071 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/runtime/stack_test.go')
-rw-r--r--src/runtime/stack_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/runtime/stack_test.go b/src/runtime/stack_test.go
index 43fc5cac55..3f02243a1e 100644
--- a/src/runtime/stack_test.go
+++ b/src/runtime/stack_test.go
@@ -585,6 +585,34 @@ func count21(n int) int { return 1 + count22(n-1) }
func count22(n int) int { return 1 + count23(n-1) }
func count23(n int) int { return 1 + count1(n-1) }
+type stkobjT struct {
+ p *stkobjT
+ x int64
+ y [20]int // consume some stack
+}
+
+// Sum creates a linked list of stkobjTs.
+func Sum(n int64, p *stkobjT) {
+ if n == 0 {
+ return
+ }
+ s := stkobjT{p: p, x: n}
+ Sum(n-1, &s)
+ p.x += s.x
+}
+
+func BenchmarkStackCopyWithStkobj(b *testing.B) {
+ c := make(chan bool)
+ for i := 0; i < b.N; i++ {
+ go func() {
+ var s stkobjT
+ Sum(100000, &s)
+ c <- true
+ }()
+ <-c
+ }
+}
+
type structWithMethod struct{}
func (s structWithMethod) caller() string {