Dear, I am not a programmer for Julia and so most likely my doubt is due to the little knowledge I have of Julia.
On a computer, I tried to produce similar codes from the Julia and R languages and got a lower performance on Julia. The codes are below:
Code Julia:
M = rand(Float64, 5000, 5000);
function inversa_loop(matriz, n)
for i = 1:n
inv(matriz)
end
end
@time inversa_loop(M, 10)
Time: 65.243 sec
Code R:
M <- matrix(runif(n = 5000^2, 0, 1), 5000, 5000)
inversa_loop <- function(matriz, n = 10){
for (i in 1:n){
solve(matriz)
}
}
system.time(inversa_loop(M))
Time: 30.231 sec
Later I tried to improve the Julia code by declaring the variable types to the inversa_loop
function to see if this would help improve performance. As we can see, yes, there was an improvement in performance considering the code below:
Modified Julia code:
M = rand(Float64, 5000, 5000);
function inversa_loop(matriz::Array{Int64,2}, n::Integer)
for i = 1:n
inv(matriz)
end
end
@time inversa_loop(M, 10)
Time: 43.654 sec
Then I noticed that maybe Iām doing an unfair comparison, since the solve
function of R is implemented in C or Fortran and the inv
is implemented in Julia. In this way, I can understand that purely Julia codes are generally more efficient than purely written R codes.
However, why common functions of linear algebra in Julia were not implemented using C/C ++? Would not that be a way to eliminate those cases where we have R functions running more efficiently than purely written codes in Julia? Perhaps there is a technical reason that justifies and I do not know. Maybe itās just a matter of philosophy of language. Perhaps the reason is the belief that in the near future the LLVM machine will evolve to the point of eliminating those differences.
I keep thinking about the case of a language user who will repeat hundreds of thousands of times Julia codes where in these repetitions exist algebraic operations that in languages like R are implemented efficiently using languages such as C or C ++. I also know that I can call C / C ++ codes in Julia, but that would be something undesirable and cumbersome for something that is so simple in other languages since they already make use of efficient codes , such as the solve
function in R.
Best regards.