Created
January 14, 2020 11:01
-
-
Save janisz/ce19a7fa94cbc99e2835a4421ccfc8d0 to your computer and use it in GitHub Desktop.
Go 1.14 defer benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bigcache | |
import "testing" | |
var sink = 0 | |
func BenchmarkNotDefered(b *testing.B) { | |
for n := 0; n < b.N; n++ { | |
notDefered() | |
} | |
b.Log(sink) | |
} | |
func BenchmarkDefered(b *testing.B) { | |
for n := 0; n < b.N; n++ { | |
defered() | |
} | |
b.Log(sink) | |
} | |
func defered() { | |
defer func() { | |
sink++ | |
}() | |
} | |
func notDefered() { | |
func() { | |
sink++ | |
}() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEXT command-line-arguments.defered(SB) /go/src/github.com/janisz/presentations/bigcache/defer_test.go | |
defer_test.go:21 0x4f65f0 64488b0c25f8ffffff MOVQ FS:0xfffffff8, CX | |
defer_test.go:21 0x4f65f9 483b6110 CMPQ 0x10(CX), SP | |
defer_test.go:21 0x4f65fd 7654 JBE 0x4f6653 | |
defer_test.go:21 0x4f65ff 4883ec48 SUBQ $0x48, SP | |
defer_test.go:21 0x4f6603 48896c2440 MOVQ BP, 0x40(SP) | |
defer_test.go:21 0x4f6608 488d6c2440 LEAQ 0x40(SP), BP | |
defer_test.go:22 0x4f660d c744240800000000 MOVL $0x0, 0x8(SP) | |
defer_test.go:22 0x4f6615 488d05dc7c0500 LEAQ 0x57cdc(IP), AX | |
defer_test.go:22 0x4f661c 4889442420 MOVQ AX, 0x20(SP) | |
defer_test.go:22 0x4f6621 488d442408 LEAQ 0x8(SP), AX | |
defer_test.go:22 0x4f6626 48890424 MOVQ AX, 0(SP) | |
defer_test.go:22 0x4f662a e8b152f3ff CALL runtime.deferprocStack(SB) | |
defer_test.go:22 0x4f662f 85c0 TESTL AX, AX | |
defer_test.go:22 0x4f6631 7510 JNE 0x4f6643 | |
defer_test.go:25 0x4f6633 90 NOPL | |
defer_test.go:25 0x4f6634 e8c75af3ff CALL runtime.deferreturn(SB) | |
defer_test.go:25 0x4f6639 488b6c2440 MOVQ 0x40(SP), BP | |
defer_test.go:25 0x4f663e 4883c448 ADDQ $0x48, SP | |
defer_test.go:25 0x4f6642 c3 RET | |
defer_test.go:22 0x4f6643 90 NOPL | |
defer_test.go:22 0x4f6644 e8b75af3ff CALL runtime.deferreturn(SB) | |
defer_test.go:22 0x4f6649 488b6c2440 MOVQ 0x40(SP), BP | |
defer_test.go:22 0x4f664e 4883c448 ADDQ $0x48, SP | |
defer_test.go:22 0x4f6652 c3 RET | |
defer_test.go:21 0x4f6653 e83818f6ff CALL runtime.morestack_noctxt(SB) | |
defer_test.go:21 0x4f6658 eb96 JMP command-line-arguments.defered(SB) | |
TEXT command-line-arguments.defered.func1(SB) /go/src/github.com/janisz/presentations/bigcache/defer_test.go | |
defer_test.go:23 0x4f6670 48ff0501a91500 INCQ command-line-arguments.sink(SB) | |
defer_test.go:24 0x4f6677 c3 RET |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEXT command-line-arguments.defered(SB) /go/src/github.com/janisz/presentations/bigcache/defer_test.go | |
defer_test.go:21 0x4f9820 64488b0c25f8ffffff MOVQ FS:0xfffffff8, CX | |
defer_test.go:21 0x4f9829 483b6110 CMPQ 0x10(CX), SP | |
defer_test.go:21 0x4f982d 764e JBE 0x4f987d | |
defer_test.go:21 0x4f982f 4883ec18 SUBQ $0x18, SP | |
defer_test.go:21 0x4f9833 48896c2410 MOVQ BP, 0x10(SP) | |
defer_test.go:21 0x4f9838 488d6c2410 LEAQ 0x10(SP), BP | |
defer_test.go:21 0x4f983d 48c7c000000000 MOVQ $0x0, AX | |
defer_test.go:21 0x4f9844 4889442408 MOVQ AX, 0x8(SP) | |
defer_test.go:21 0x4f9849 c644240700 MOVB $0x0, 0x7(SP) | |
defer_test.go:22 0x4f984e 488d0503e80400 LEAQ 0x4e803(IP), AX | |
defer_test.go:22 0x4f9855 4889442408 MOVQ AX, 0x8(SP) | |
defer_test.go:25 0x4f985a c644240700 MOVB $0x0, 0x7(SP) | |
defer_test.go:25 0x4f985f e83c000000 CALL command-line-arguments.defered.func1(SB) | |
defer_test.go:25 0x4f9864 488b6c2410 MOVQ 0x10(SP), BP | |
defer_test.go:25 0x4f9869 4883c418 ADDQ $0x18, SP | |
defer_test.go:25 0x4f986d c3 RET | |
defer_test.go:25 0x4f986e e81d70f3ff CALL runtime.deferreturn(SB) | |
defer_test.go:25 0x4f9873 488b6c2410 MOVQ 0x10(SP), BP | |
defer_test.go:25 0x4f9878 4883c418 ADDQ $0x18, SP | |
defer_test.go:25 0x4f987c c3 RET | |
defer_test.go:21 0x4f987d e8be5cf6ff CALL runtime.morestack_noctxt(SB) | |
defer_test.go:21 0x4f9882 eb9c JMP command-line-arguments.defered(SB) | |
TEXT command-line-arguments.defered.func1(SB) /go/src/github.com/janisz/presentations/bigcache/defer_test.go | |
defer_test.go:23 0x4f98a0 48ff05b1681600 INCQ command-line-arguments.sink(SB) | |
defer_test.go:24 0x4f98a7 c3 RET |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
benchstat go_version_go1.13.6_linux_amd64.txt go_version_go1.14beta1_linux_amd64.txt | |
name old time/op new time/op delta | |
NotDefered 1.31ns ± 4% 1.39ns ± 9% +5.40% (p=0.005 n=10+10) | |
NotDefered-2 1.28ns ± 0% 1.36ns ± 6% +6.09% (p=0.000 n=7+10) | |
NotDefered-3 1.28ns ± 0% 1.42ns ± 2% +10.64% (p=0.000 n=8+8) | |
NotDefered-4 1.28ns ± 0% 1.35ns ± 5% +5.63% (p=0.000 n=6+10) | |
Defered 32.0ns ± 2% 2.7ns ± 1% -91.66% (p=0.000 n=10+10) | |
Defered-2 31.6ns ± 0% 2.7ns ± 3% -91.39% (p=0.000 n=10+10) | |
Defered-3 31.6ns ± 0% 2.7ns ± 1% -91.56% (p=0.000 n=10+8) | |
Defered-4 31.5ns ± 0% 2.7ns ± 0% -91.51% (p=0.000 n=9+8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment