Open
Description
What version of Go are you using (go version
)?
$ go version go version go1.17.1 linux/amd64
Does this issue reproduce with the latest release?
Yes
What did you do?
package functions
import "testing"
const N = 1<<12
var buf = make([]byte, N)
var r [128][N]byte
func Benchmark_SliceToArray_Named(b *testing.B) {
for i := 0; i < b.N; i++ {
r[i&127] = SliceToArray_Named(buf)
}
}
func Benchmark_SliceToArray_Unnamed(b *testing.B) {
for i := 0; i < b.N; i++ {
r[i&127] = SliceToArray_Unnamed(buf)
}
}
func SliceToArray_Named(b []byte) (ret [N]byte) {
ret = *(*[N]byte)(b)
return
}
func SliceToArray_Unnamed(b []byte) [N]byte {
return *(*[N]byte)(b)
}
What did you expect to see?
No performance difference
What did you see instead?
The named reult version is slower than the anonymous result version.
Benchmark_SliceToArray_Named-4 2983450 397.7 ns/op
Benchmark_SliceToArray_Unnamed-4 4106510 293.0 ns/op
It looks this is related to code inlining.