Skip to content

Commit

Permalink
runtime: add BenchmarkStackCopyWithStkobj
Browse files Browse the repository at this point in the history
For benchmarking and improving recent stkobj-related changes.

Co-Authored-By: Cherry Mui <[email protected]>
Change-Id: I34c8b1a09e4cf98547460882b0d3908158269f57
Reviewed-on: https://go-review.googlesource.com/c/go/+/354071
Trust: Josh Bleecher Snyder <[email protected]>
Run-TryBot: Josh Bleecher Snyder <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
  • Loading branch information
josharian and cherrymui committed Oct 5, 2021
1 parent 0b4d499 commit 75773b0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/runtime/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 75773b0

Please sign in to comment.