Hi all fine people here!

I am just interested in knowing if anyone here sees any performance improvements in my code. Either algorithmically or Julia specific.

The code in question is a function which calculates local maxima and minima.

The function does this by calculating the rolling maximum (the maximum in a moving window) and uses that to obtain local optima.

Below is the code! **vect** is usually on the order of 1000 entries.

```
using DataStructures
function rolling_optima(vect::Any, win_size::Integer; debug=false)
roll_max = zeros(Float64, length(vect))
roll_min = zeros(Float64, length(vect))
opt_index = zeros(Int16, length(vect))
opt_type = zeros(Int8, length(vect))
d_max = Deque{Float64}()
d_min = Deque{Float64}()
win_forward = win_size
win_backward = win_forward*2
opt_ind = 0
#comp = 10
@inbounds for i in eachindex(vect)
@inbounds for k in 1:length(d_max)
if vect[i] >= front(d_max) popfirst!(d_max)
else break end
end
@inbounds for k in 1:length(d_min)
if vect[i] <= front(d_min) popfirst!(d_min)
else break end
end
pushfirst!(d_max,vect[i])
pushfirst!(d_min,vect[i])
j = i + 1 - win_forward
if j >= 1
roll_max[i] = back(d_max)
roll_min[i] = back(d_min)
if vect[j] == back(d_max)
if roll_max[i] == roll_max[j]
if j-win_backward > 0
if roll_max[j] > maximum(vect[j-win_backward:j-1])
opt_ind +=1
opt_index[opt_ind] = j
opt_type[opt_ind] = 1
end
end
end
pop!(d_max)
end
if vect[j] == back(d_min)
if roll_min[i] == roll_min[j]
if j-win_backward > 0
if roll_min[j] < minimum(vect[j-win_backward:j-1])
opt_ind +=1
opt_index[opt_ind] = j
opt_type[opt_ind] = -1
end
end
end
pop!(d_min)
end
end
end
opt_index = opt_index[1:opt_ind]
opt_type = opt_type[1:opt_ind]
if debug
return opt_index, opt_type, roll_max, roll_min
else
return opt_index, opt_type
end
end
```