Julia's arrays grow by doubling, see 
http://en.wikipedia.org/wiki/Dynamic_array

Since you're appending elements to an array, julia has to have somewhere to 
put them---and when there's no spare capacity, julia has to allocate a new 
array and copy the entire thing. So some allocations are much bigger than what 
you're adding, but others (as you can see) are 0.

This is a marked improvement over Matlab, which makes a copy of your entire 
array each time you add 1 element.

Best,
--Tim

On Friday, December 19, 2014 10:00:28 AM John Drummond wrote:
> For the following code (julia 0.3.3 in windows 7 ) I don't understand what
> the bytes allocated in @time means
> 
> All I'm doing each time is adding 10  8 byte integers
> 
> Thanks for any thoughts
> 
> julia> @time c = [1,2]
> elapsed time: 3.32e-6 seconds (144 bytes allocated)
> 2-element Array{Int64,1}:
>  1
>  2
> 
> julia> sizeof(c)
> 16
> 
> 
> julia> @time for x in 30:39 push!(c, x) end
> elapsed time: 2.717e-6 seconds (256 bytes allocated)
> 
> julia> @time for x in 30:39 push!(c, x) end
> elapsed time: 2.717e-6 seconds (288 bytes allocated)
> 
> julia> @time for x in 30:39 push!(c, x) end
> elapsed time: 2.112e-6 seconds (0 bytes allocated)
> 
> julia> @time for x in 30:39 push!(c, x) end
> elapsed time: 3.321e-6 seconds (640 bytes allocated)
> 
> julia> sizeof(c)
> 336

Reply via email to