mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: aggregate defer allocations
benchmark old ns/op new ns/op delta BenchmarkDefer 165 113 -31.52% BenchmarkDefer10 155 103 -33.55% BenchmarkDeferMany 216 158 -26.85% benchmark old allocs new allocs delta BenchmarkDefer 1 0 -100.00% BenchmarkDefer10 1 0 -100.00% BenchmarkDeferMany 1 0 -100.00% benchmark old bytes new bytes delta BenchmarkDefer 64 0 -100.00% BenchmarkDefer10 64 0 -100.00% BenchmarkDeferMany 64 66 3.12% Fixes #2364. R=ken2 CC=golang-dev https://golang.org/cl/7001051
This commit is contained in:
parent
e09f1e7a46
commit
0de71619ce
4 changed files with 180 additions and 39 deletions
|
|
@ -38,3 +38,44 @@ func BenchmarkIfaceCmpNil100(b *testing.B) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDefer(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
defer1()
|
||||
}
|
||||
}
|
||||
|
||||
func defer1() {
|
||||
defer func(x, y, z int) {
|
||||
if recover() != nil || x != 1 || y != 2 || z != 3 {
|
||||
panic("bad recover")
|
||||
}
|
||||
}(1, 2, 3)
|
||||
return
|
||||
}
|
||||
|
||||
func BenchmarkDefer10(b *testing.B) {
|
||||
for i := 0; i < b.N/10; i++ {
|
||||
defer2()
|
||||
}
|
||||
}
|
||||
|
||||
func defer2() {
|
||||
for i := 0; i < 10; i++ {
|
||||
defer func(x, y, z int) {
|
||||
if recover() != nil || x != 1 || y != 2 || z != 3 {
|
||||
panic("bad recover")
|
||||
}
|
||||
}(1, 2, 3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDeferMany(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
defer func(x, y, z int) {
|
||||
if recover() != nil || x != 1 || y != 2 || z != 3 {
|
||||
panic("bad recover")
|
||||
}
|
||||
}(1, 2, 3)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue