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/CAOyqgcUHurTzm5c%3DoU3ka2F8u4vew74dFKf32QuqSe7KRdBhwQ%40mail.gmail.com.

Reply via email to