I am relatively new to Julia and I wrote some scripts my main issue is that my scripts perform always poor and I don’t understand why or what I am doing wrong.
Take this code as example where I am failing:
dimension = 2
typeof(dimension)
dimension2::Int = 2
typeof(dimension2)
testMatrix = ones(1500, dimension)
countMatrix = zeros(Int, 5, 5)
@elapsed for NN in 1:1000
for k in eachindex(testMatrix[:, 1])
coordMatrix= zeros(Int, dimension)
# due to precision issues, we subtract a small value from the values
for i in 1:dimension
coordMatrix[i] = trunc(testMatrix[k, i] / 4.3) + 1
end
#nTuple = Tuple(coordMatrix)
#countMatrix[coordMatrix[1], coordMatrix[2]] += 1
#countMatrix[coordMatrix...] += 1
end
end
The code as it is needs on my PC about 1.02 seconds to run.
But when I replace in the for k loop ‘dimension’ by ‘dimension2’ the same code runs 40 % faster (about 0.608 seconds).
Why is that the case? typeof(dimension) and typeof(dimension2) shows me in botch cases “Int64” as datatype?
Next problem:
when I leave “dimension” and uncomment the line
ntuple = Tuple(coordMatrix)
the runtime jumps from 1.02 to 1.50 seconds. But this creates just a tuple of a vector with just 2 entries.
I use Win 10, 64bit and Julia 1.11.4. I get the same results, no matter if I work in the REPL or in VS Code.