Great, thank you.
On Friday, December 19, 2014 6:37:03 PM UTC, John Myles White wrote: > > The problem is that your let block is not a proper function body. You need > to time things inside of a function body: > > julia> function foo() > @time a1 = zeros(Int64,10000000) > @time resize!(a1, 1000) > @time resize!(a1, 10000000) > @time resize!(a1, 10000000) > @time resize!(a1, 20000000) > end > foo (generic function with 1 method) > > julia> foo() > elapsed time: 0.039935728 seconds (80000048 bytes allocated) > elapsed time: 8.61e-6 seconds (0 bytes allocated) > elapsed time: 4.45e-7 seconds (0 bytes allocated) > elapsed time: 2.71e-7 seconds (0 bytes allocated) > elapsed time: 0.000365734 seconds (160000000 bytes allocated) > > -- John > > On Dec 19, 2014, at 1:34 PM, John Drummond <joh...@gmail.com <javascript:>> > wrote: > > > Sorry to be stupid - but this also helps me understand things for > another question: > > So bytes allocated would be the underlying usage of memory. > > > > in which case with > > julia> let > > @time a1 = zeros(Int64,10000000) > > @time resize!(a1, 1000) > > @time resize!(a1, 10000000) > > @time resize!(a1, 10000000) > > @time resize!(a1, 20000000) > > end > > elapsed time: 0.015554722 seconds (80000152 bytes allocated) > > elapsed time: 5.735e-6 seconds (80 bytes allocated) > > elapsed time: 2.113e-6 seconds (80 bytes allocated) > > elapsed time: 2.113e-6 seconds (80 bytes allocated) > > elapsed time: 0.027380439 seconds (160000080 bytes allocated) > > 20000000-element Array{Int64,1}: > > > > what's the 80 bytes allocated when I'm just changing the length I'm > using? > > > > And will increasing the size beyond the maximum always copy the whole > array? > > > > Many thanks for clarifying this. > > > > > > > > > > > > On Friday, December 19, 2014 6:12:42 PM UTC, Tim Holy wrote: > > 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 > > > >