Hello, so I am an undergrad porting code from MatLab into Julia with the objective of improving performance, but so far performance has been disappointing: Julia: 58 seconds/instance, MatLab: 18 seconds/instance (thousands of simulations are being run - so the time adds up to hours).
I’ve read and implemented everything obviously applicable in performance tips, avoiding global variables, annotating all types, pre-allocating memory, moving code into small functions, all of which did speed the program up, but only to the current 58 seconds/instance.
For reference, the best possible time I can achieve for the simulation is ~8 seconds/instance with a (very optimized) Rust program (which to me implies that Julia is going to struggle to improve on the Matlab - given the already strong performance of the MatLab code).
For reference the code consists of multiplying lots of slices of arrays. Below is an example of one the most ‘hot’ functions. Is there a better, more efficient way? (Julia also seems to consume similar amounts of memory to MatLab but way more - like orders of magnitude more - than Rust)
function A(b::Matrix{Float64},x::Float64,v::Float64,c::Matrix{Float64},d::Matrix{Float64})::Terms
@fastmath @inbounds var_1 = v*x*(c[1,3]*b[1,:]-d[1,3]*b[3,:])
@fastmath @inbounds var_2 = v*x*(c[3,7]*b[3,:]-d[3,7]*b[7,:])
...
Terms(var_1, var_2 ...
end
(For those of you wondering why I deleted the earlier question of the same type - I accidentally posted it before I was done writing it up - probably just should of edited it).