Thank you, yes, I took a look at the assembly and both generate MMX code, I did not check the preamble though. That said, the result is very consistent on my machine. Surprise.
I am happy with no-overhead, so everything is good. On Mon, Apr 18, 2022 at 9:37 PM Ian Lance Taylor <i...@golang.org> wrote: > On Mon, Apr 18, 2022 at 1:14 PM Feng Tian <feng...@gmail.com> wrote: > > > > Hi, I have the following simple benchmark code, > > > > https://go.dev/play/p/m1ClnbdbdWi > > > > I run this on my laptop since Go playground does not run benchmark > code. The strange thing is that Copy of float64 is slower than copy using > generics. I can imagine generics may add no overhead, but how can it be > faster? > > > > ftian@DESKTOP-16FCU43:~/tmp$ go test -bench=. > > goos: linux > > goarch: amd64 > > pkg: a > > cpu: 11th Gen Intel(R) Core(TM) i7-11370H @ 3.30GHz > > BenchmarkCopy-8 5693944 221.7 ns/op > > BenchmarkCopyG-8 8885454 137.1 ns/op > > PASS > > ok a 2.838s > > The numbers for this kind of micro-benchmark can be deceptive. For > example, they can be highly affected by alignment of the instruction > loop. I don't know exactly what is happening for you. I compiled the > code with "go test -c" and disassembled it: both benchmark functions > contained exactly the same instructions. > > Ian > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAFjtmHVXN7d4UUTCOUtJ%3Drjk3FY%2B9gCixwmZWPd_a1xZpRVdSA%40mail.gmail.com.