Open liveresume opened 7 years ago
Can you run @time sma([1:20], 5)
again and see if the speed increases? The first time you run it, most of the time is due to compilation.
For example:
julia> using RingArrays
julia> function sma(arr, P)
tlen = length(arr)
tarr = zeros(tlen)
ring = RingArray{Int, 1}(max_blocks=P, block_size=(1,), data_length=tlen)
for i in 1:tlen-P+1
load_block(ring, [arr[i]])
tarr[i+P-1] = mean(ring[ring.range])
end
tarr
end
sma (generic function with 1 method)
julia> @time sma([1:20], 5)
0.086269 seconds (99.22 k allocations: 4.309 MB)
1-element Array{Float64,1}:
0.0
julia> @time sma([1:20], 5)
0.000014 seconds (12 allocations: 864 bytes)
1-element Array{Float64,1}:
0.0
Why is this running so slowly?