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.
>

Reply via email to