23.04.2025 - julia.txt
It's been a few years, and now I'm trying again to learn (to love) Julia (the programming language).
One very important thing which was not clear to me from the get-go, is that if you want to run a Julia file multiple times, you absolutely need to do it from the REPL.
If you call it from the command line, Julia will JIT-compile everything again and again.
For example, assume there's a file time_test.jl containing only a single line,
For example, assume there's a file time_test.jl containing only a single line,
@time using Plots
In the above example, we import Plots and measure how much time it took. Running this file three times in the shell will output
>>> julia time_test.jl
4.839571 seconds (1.68 M allocations: 102.641 MiB, 3.99% gc time, 2.73% compilation time)
>>> julia time_test.jl
4.732288 seconds (1.68 M allocations: 102.637 MiB, 4.22% gc time, 2.57% compilation time)
>>> julia time_test.jl
4.592076 seconds (1.68 M allocations: 102.642 MiB, 4.21% gc time, 2.66% compilation time)
Now, if I open the Julia REPL, and run the same file three times (by calling include("time_test.jl")), I get
>>> julia
julia> include("time_test.jl")
4.198994 seconds (1.44 M allocations: 88.602 MiB, 6.02% gc time, 3.37% compilation time)
julia> include("time_test.jl")
0.001341 seconds (326 allocations: 18.141 KiB)
julia> include("time_test.jl")
0.001429 seconds (326 allocations: 18.141 KiB)
Adding another library will not cause Julia to recompile entirely; only the new library will be compiled.
@time using Plots
@time using ITensors
will result in
julia> include("time_test.jl")
0.001315 seconds (326 allocations: 18.141 KiB)
3.173273 seconds (1.03 M allocations: 61.453 MiB, 10.38% gc time, 6.27% compilation time)
julia> include("time_test.jl")
0.001294 seconds (326 allocations: 18.141 KiB)
0.001292 seconds (326 allocations: 18.148 KiB)
This might be clearer to some. It wasn't to me.