4 ms·
Well, the assembler looks the same to me too, but I can confirm different runtimes on two different machines (fast is always faster here). $ ./main.test -tes
by JepZ 9y ago
Well, the assembler looks the same to me too, but I can confirm different runtimes on two different machines (fast is always faster here).
$ ./main.test -test.bench . -test.cpuprofile=test.profile
goos: linux
goarch: amd64
BenchmarkInLoop-8 2000000000 0.42 ns/op
BenchmarkOutLoop-8 2000000000 0.47 ns/op
PASS
(pprof) disasm fast
Total: 1.86s
ROUTINE ======================== command-line-arguments.fast
990ms 990ms (flat, cum) 53.23% of Total
. . 4ed7b0: MOVQ 0x8(SP), AX ;mem_test.go:16
. . 4ed7b5: XORL CX, CX
. . 4ed7b7: MOVQ CX, DX
. . 4ed7ba: JMP 0x4ed7c6 ;mem_test.go:19
650ms 650ms 4ed7bc: LEAQ 0x1(CX), BX ;command-line-arguments.fast mem_test.go:19
. . 4ed7c0: MOVQ CX, DX ;mem_test.go:19
10ms 10ms 4ed7c3: MOVQ BX, CX ;command-line-arguments.fast mem_test.go:19
330ms 330ms 4ed7c6: CMPQ AX, CX
. . 4ed7c9: JL 0x4ed7bc ;mem_test.go:19
. . 4ed7cb: MOVQ DX, 0x10(SP) ;mem_test.go:23
(pprof) disasm slow
Total: 1.86s
ROUTINE ======================== command-line-arguments.slow
870ms 870ms (flat, cum) 46.77% of Total
. . 4ed780: MOVQ 0x8(SP), AX ;mem_test.go:7
. . 4ed785: XORL CX, CX
. . 4ed787: MOVQ CX, DX
. . 4ed78a: JMP 0x4ed796 ;mem_test.go:9
560ms 560ms 4ed78c: LEAQ 0x1(CX), BX ;command-line-arguments.slow mem_test.go:9
. . 4ed790: MOVQ CX, DX ;mem_test.go:9
20ms 20ms 4ed793: MOVQ BX, CX ;command-line-arguments.slow mem_test.go:9
290ms 290ms 4ed796: CMPQ AX, CX
. . 4ed799: JL 0x4ed78c ;mem_test.go:9
. . 4ed79b: MOVQ DX, 0x10(SP) ;mem_test.go:13