Skip to content

Instantly share code, notes, and snippets.

@shirou
Last active August 25, 2017 10:16
Show Gist options
  • Save shirou/9cd73d19382882d3a1b7f0cc490810df to your computer and use it in GitHub Desktop.
Save shirou/9cd73d19382882d3a1b7f0cc490810df to your computer and use it in GitHub Desktop.
go test -bench . -benchmem
BenchmarkOk-4 2000000000 0.32 ns/op 0 B/op 0 allocs/op
BenchmarkErr-4 2000000000 0.32 ns/op 0 B/op 0 allocs/op
"".BenchmarkOk t=1 size=35 args=0x8 locals=0x0
0x0000 00000 (a_test.go:8) TEXT "".BenchmarkOk(SB), $0-8
0x0000 00000 (a_test.go:8) FUNCDATA $0, gclocals·a36216b97439c93dafebe03e7f0808b5(SB)
0x0000 00000 (a_test.go:8) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0x0000 00000 (a_test.go:10) MOVQ "".b+8(FP), AX
0x0005 00005 (a_test.go:9) MOVQ $0, CX
0x0007 00007 (a_test.go:10) MOVQ 200(AX), DX
0x000e 00014 (a_test.go:10) CMPQ CX, DX
0x0011 00017 (a_test.go:10) JGE $0, 34
0x0013 00019 (a_test.go:10) INCQ CX
0x0016 00022 (a_test.go:10) MOVQ 200(AX), DX
0x001d 00029 (a_test.go:10) CMPQ CX, DX
0x0020 00032 (a_test.go:10) JLT $0, 19
0x0022 00034 (a_test.go:16) RET
0x0000 48 8b 44 24 08 31 c9 48 8b 90 c8 00 00 00 48 39 H.D$.1.H......H9
0x0010 d1 7d 0f 48 ff c1 48 8b 90 c8 00 00 00 48 39 d1 .}.H..H......H9.
0x0020 7c f1 c3 |..
"".BenchmarkErr t=1 size=35 args=0x8 locals=0x0
0x0000 00000 (a_test.go:17) TEXT "".BenchmarkErr(SB), $0-8
0x0000 00000 (a_test.go:17) FUNCDATA $0, gclocals·a36216b97439c93dafebe03e7f0808b5(SB)
0x0000 00000 (a_test.go:17) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0x0000 00000 (a_test.go:19) MOVQ "".b+8(FP), AX
0x0005 00005 (a_test.go:18) MOVQ $0, CX
0x0007 00007 (a_test.go:19) MOVQ 200(AX), DX
0x000e 00014 (a_test.go:19) CMPQ CX, DX
0x0011 00017 (a_test.go:19) JGE $0, 34
0x0013 00019 (a_test.go:19) INCQ CX
0x0016 00022 (a_test.go:19) MOVQ 200(AX), DX
0x001d 00029 (a_test.go:19) CMPQ CX, DX
0x0020 00032 (a_test.go:19) JLT $0, 19
0x0022 00034 (a_test.go:25) RET
0x0000 48 8b 44 24 08 31 c9 48 8b 90 c8 00 00 00 48 39 H.D$.1.H......H9
0x0010 d1 7d 0f 48 ff c1 48 8b 90 c8 00 00 00 48 39 d1 .}.H..H......H9.
0x0020 7c f1 c3
package main
import (
"errors"
"testing"
)
func BenchmarkOk(b *testing.B) {
var j int
for i := 0; i < b.N; i++ {
ok, _ := test()
if !ok {
j++ // なんか処理をいれたかっただけ
}
}
}
func BenchmarkErr(b *testing.B) {
var j int
for i := 0; i < b.N; i++ {
_, err := test()
if err != nil {
j++ // なんか処理をいれたかっただけ
}
}
}
var (
ErrorTest = errors.New("test")
)
func test() (ok bool, err error) {
return false, ErrorTest
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment