What happens if you use sizehint!() with dynamic()?

On Sunday, November 15, 2015 at 3:35:45 PM UTC-8, Steven G. Johnson wrote:
>
> function prealloc(n)
>     a = Array(Int, n)
>     for i = 1:n
>         a[i] = i
>     end
>     return a
> end
> function dynamic(n)
>     a = Int[]
>     for i = 1:n
>         push!(a, i)
>     end
>     return a
> end
> @time prealloc(10^7);
> @time dynamic(10^7);
>
>
> On my machine, the preallocated version is 2.5–3x faster.  A significant 
> but not overwhelming margin.
>

Reply via email to