OK, ran a test.  And the difference is pretty dramatic.  Look:

  | | |_| | | | (_| |  |  Version 0.5.0-rc4+0 (2016-09-09 01:43 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-pc-linux-gnu

julia> include("testArray.jl")

julia> testShift()
using: A=[0; A[1:end-1]]
elapsed time: *5.341734653* seconds
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] 9
using unshift! and deleteat!
elapsed time: *0.00066514* seconds
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] 9

function testShift()
>
>     A=[1:100000;]
>
>     println("using: A=[0; A[1:end-1]]")
>
>     tic()
>
>     for i=1:10000
>
>         A=[0; A[1:end-1]]
>
>     end
>
>     toc()
>
>     println(A[1:20], " ", A[10009])
>
>     
>
>     B=[1:100000;]
>
>     println("using unshift! and deleteat!")
>
>     tic()
>
>     for i=1:10000
>
>         unshift!(B, 0)
>
>         deleteat!(B, length(A))
>
>     end
>
>     toc()
>
>     println(B[1:20], " ", B[10009])
>
>     nothing
>
> end
>
>
>
On Sunday, September 18, 2016 at 9:17:11 PM UTC+8, David P. Sanders wrote:
>
> You should also benchmark the simple for loop. Please report back with the 
> results. 

Reply via email to