<https://lh3.googleusercontent.com/-KWZ3N68FiiE/VhKecOV1OeI/AAAAAAAAAag/ZqiuV80G9fY/s1600/density.png>
I did not know about this fill!-function before this thread, but I get
A = rand(3000,3000); # guess this could be zeroes just as well...
fillt = [@elapsed fill!(A, 0.) for i = 1:100]
colot = [@elapsed A[:] = 0. for i = 1:100]
minimum(fillt)
#0.007782668
minimum(colont)
#0.013952048
mean(fillt)
#0.008371900670000001
mean(colont)
#0.014339453529999999
And a density plot (green is fill!, red is [:]=0.)
On Monday, October 5, 2015 at 11:30:04 AM UTC-4, Sisyphuss wrote:
>
> On my machine, it is not the same:
>
> @time A[:]=0.;
> @time fill!(A,0.);
> 0.033513 seconds (5 allocations: 176 bytes)
> 0.013535 seconds (4 allocations: 160 bytes)
>
> On Monday, October 5, 2015 at 4:44:52 PM UTC+2, Steven G. Johnson wrote:
>>
>>
>>
>> On Monday, October 5, 2015 at 10:21:08 AM UTC-4, Patrick Kofod Mogensen
>> wrote:
>>>
>>> Say I have an array with come results of a computation, and I have to do
>>> this computation many times. I want to use the memory I've already
>>> allocated, but I want to start from zero. Is the best way to zero an array:
>>>
>>> A = rand(3000,3000)
>>> A[:] = 0.
>>>
>>> Or is there a better way?
>>>
>>
>> No, I don't think so.
>>
>> A = rand(3000,3000)
>> @time A[:] = 0.
>> @time fill!(A, 0.);
>> @time ccall(:memset, Ptr{Void}, (Ptr{Void}, Cint, Csize_t), A, 0,
>> sizeof(A))
>>
>>
>> all give about the same time on my machine.
>>
>