I am trying to optimise a piece of my code. I have currently used mutable struct
to declare variable types. Following which I assign values to them,
mutable struct Par
N::Int64 ;
n::Int64 ;
end
mutable struct Mat
A::Array{Int64,2} ;
θₜ::Array{Float64,2} ;
Atemp::Array{Int64,2} ;
Asep::Array{Float64,2} ;
allag::Array{Float64,2} ;
end
p = Par(1000,5000) ;
m = Mat(zeros(Int64,p.N,p.N),zeros(Float64,p.n,p.N),zeros(Int64,p.N,p.N),zeros(Float64,p.N,p.N),zeros(Float64,p.N,p.N)) ;
I would want to increase values of N
and n
in subsequent simulations. But I notice already that initialising the matrices themselves take time of the order of 10^-3,
using BenchmarkTools
@btime m = Mat(zeros(Int64,p.N,p.N),zeros(Float64,p.n,p.N),zeros(Int64,p.N,p.N),zeros(Float64,p.N,p.N),zeros(Float64,p.N,p.N)) ;
13.360 ms (21 allocations: 68.67 MiB)
Is there a faster/optimal way of doing this?