I am quite new to Julia and programming in general so I was wondering if I have implemented your suggestions correctly. Here is my new code;

```
# inline finite difference function
@inline function new_derivative2!(y ,i)
# Removed if statements
dy = -y[i-2] + 16*y[i-1] - 30*y[i] + 16*y[i+1] - y[i+2]
dy = dy / (12 * 0.001^2)
return dy
end
function new_QC!(E, ϵ)
Q_C = Array{Float64, 3}(undef, 5, length(ϵ), length(ϵ)) # Define array
dx = 0.001 # removing invariant calculation
for k =1:5
for j = 1:length(ϵ)
Q_C[k,1,j] = (35*E[k,1,j] - 104*E[k,2,j] + 114*E[k,3,j] - 56*E[k,4,j] + 11*E[k,5,j]) / (12 * dx^2)
Q_C[k,2,j] = (11*E[k,1,j] -20*E[k,2,j] + 6*E[k,3,j] + 4*E[k,4,j] - E[k,5,j]) / (12 * dx^2)
for i=3:(length(ϵ)-2)
Q_C[k,i,j] = new_derivative2!(E[k,:,j], i)
end
Q_C[k,520,j] = (-E[k,517,j] + 4*E[k,518,j] + 6*E[k,519,j] - 20*E[k,520,j] + 11*E[k,521,j]) / (12 * dx^2)
Q_C[k,521,j] = (11*E[k,517,j] - 56*E[k,518,j] + 114*E[k,519,j] - 104*E[k,520,j] + 35*E[k,521,j]) / (12 * dx^2)
end
end
return Q_C
end
```

Benchmarks of old and new:

##
Old

```
julia> @benchmark QC!(E, ϵ)
BenchmarkTools.Trial: 6 samples with 1 evaluation.
Range (min … max): 925.521 ms … 1.122 s ┊ GC (min … max): 25.53% … 24.48%
Time (median): 977.854 ms ┊ GC (median): 25.28%
Time (mean ± σ): 995.556 ms ± 77.650 ms ┊ GC (mean ± σ): 25.16% ± 0.41%
█ █ █ █ █ █
█▁█▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁
926 ms Histogram: frequency by time 1.12 s <
Memory estimate: 5.51 GiB, allocs estimate: 1357207.
```

##
New

```
julia> @benchmark new_QC!(E,ϵ)
BenchmarkTools.Trial: 6 samples with 1 evaluation.
Range (min … max): 894.819 ms … 1.077 s ┊ GC (min … max): 25.53% … 24.80%
Time (median): 951.854 ms ┊ GC (median): 25.24%
Time (mean ± σ): 978.050 ms ± 72.613 ms ┊ GC (mean ± σ): 25.19% ± 0.28%
█ █ █ █ █ █
█▁▁▁▁▁▁▁▁▁▁▁▁█▁▁█▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁█ ▁
895 ms Histogram: frequency by time 1.08 s <
Memory estimate: 5.47 GiB, allocs estimate: 1346787.
```

Thank you