This looks like it is all due to the extra zeroing required for the Copy 
test.  CloneWithAppend does not need to zero the newly allocated slice 
before copying the contents of x into it.  CloneWithCopy does.

Benchmark_CloneWithAppend-4      3000    480247 ns/op
Benchmark_CloneWithCopy-4        1000   1109543 ns/op

If I hack the runtime to remove the no-zeroing-on-append optimization, the 
performance difference disappears (it actually reverses):

Benchmark_CloneWithAppend-4      1000   1443989 ns/op
Benchmark_CloneWithCopy-4        1000   1161912 ns/op

I'm actually quite surprised that the differences seen here are so large. 
 I don't understand how it can be more than a factor of 2.  Zeroing should 
be no more expensive than copying.
If anyone has any idea why, let me know.


On Tuesday, June 27, 2017 at 7:04:33 PM UTC-7, Kevin Malachowski wrote:
>
> Hit send too early... Your benchmarks do show that something is strange 
> hen comparing the make (memclr) and copy (memory copy) cases. Out of my 
> element here :) 
>
> On Jun 27, 2017 7:01 PM, "Kevin Malachowski" <ke...@chowski.com 
> <javascript:>> wrote:
>
>> But memclr+copy is slower than just copy, right?
>>
>> On Jun 27, 2017 6:53 PM, "T L" <tapi...@gmail.com <javascript:>> wrote:
>>
>>>
>>>
>>> On Tuesday, June 27, 2017 at 8:55:48 PM UTC-4, Kevin Malachowski wrote:
>>>>
>>>> It's best to compare the assembly, but my guess: 'make' has to zero out 
>>>> the memory, whereas allocation using append does not.
>>>
>>>
>>> allocation using append will copy each element, which should be slower 
>>> than memclr.
>>>
>>> -- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "golang-nuts" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/golang-nuts/nDYYHKwvYhQ/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to 
>>> golang-nuts...@googlegroups.com <javascript:>.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to