On Sun, May 30, 2021 at 4:04 AM Jan Mercl <0xj...@gmail.com> wrote:
>
> Within the benchmark loops of the linked code a sufficiently smart compiler
> can optimize the source values away completely and/or collapse all writes to
> the destination values to a single write.
For example, here are the
gcflags=-S shows the code of copy 3-field and 4-field structs:
// struct{a, b, c int}
0x0034 00052 (valuecopy.go:223)MOVQ$0, "".struct3_0(SB)
0x003f 00063 (valuecopy.go:223)XORPSX0, X0
0x0042 00066 (valuecopy.go:223)MOVUPSX0, "".struct3_0+8(SB)
// struc
Within the benchmark loops of the linked code a sufficiently smart compiler
can optimize the source values away completely and/or collapse all writes
to the destination values to a single write.
Have you looked at the actual code the CPU executes?
>
>
--
You received this message because you ar
I believe it is save to say, even without other benchmarks, that a) you are
correct that the cost is "unpredictable"ยน and b) that will always be the
case. The compiler will always chose different strategies for differently
sized values and if not that, the architecture of computers will have
differ
On Sunday, May 30, 2021 at 12:28:55 AM UTC-4 Kurtis Rader wrote:
> On Sat, May 29, 2021 at 8:50 PM tapi...@gmail.com
> wrote:
>
>> The benchmark code: https://play.golang.org/p/bC1zO14eNeh
>>
> ...
>>
> From the benchmark result, it looks
>> * the cost of copying a [13]int value is much large
On Sat, May 29, 2021 at 8:50 PM tapi...@gmail.com
wrote:
> The benchmark code: https://play.golang.org/p/bC1zO14eNeh
> ...
> From the benchmark result, it looks
> * the cost of copying a [13]int value is much larger than copying a
> [12]int value.
> * the cost of copying a struct{a, b, c int} val