A problem that confuses me, plan9 is slower than the go code

Code snippet of go:

Func tryAdd(seconds, servid int64) int64
Func tryAdd2(seconds, servid int64) int64 {
     Return seconds + servid
}

Code snippet of plan9:

TEXT ·tryAdd(SB), NOSPLIT, $0-24
     MOVQ x+0(FP), BX
     MOVQ y+8(FP), BP
     ADDQ BP, BX
     MOVQ BX, ret+16(FP)
     RET

The pressure test results, tryAdd2 (go) is nearly 4 times faster than tryAdd (plan9)
BenchmarkTryAdd-4 2000000000 1.34 ns/op
BenchmarkTryAdd2-4 2000000000 0.24 ns/op

Maybe the addition is optimized away in the go version. I found this https://rakyll.org/go-tool-flags/ Try to run the code without optimisation?

$ go build -gcflags
Used to pass flags to the Go compiler. go tool compile -help lists all the flags that can be passed to the compiler.

For example, to disable compiler optimizations and inlining, you can use the following the gcflags.

$ go build -gcflags="-N -l"

Thank you very much for your reply!
It’s really the reason for inlining, they’re going to be the same after closing inlining.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.