In addition, if this is the first run after starting Julia, then this is what you’ll see discussed as “TTFP” (time to first plot) because for a long time Plots.jl was particularly bad. But “TTFG” with Zygote is around 12 seconds, sadly. This you should roughly think of as compilation time. Ideally the compiled code would all be stored somewhere to re-use, except the bits that have changed…
Thanks for your responses. When I removed the @btime and run the script again, it took about 10 seconds. I suspect it is the using statements that cause the delay (I used debug printing), although I do not know why.
That would help. For most things, I just use the REPL and Revise.
The problem with trying to script like this is that Julia does not have the chance to cache the compilation. From a cold start. Julia not only has to startup, but it also needs to compile your code again.
For starting out, I might use Revise with includet to start prototyping a function. After I edit the function in a separate file, Revise will reload the changed file for me. The first execution of the changed function will be slower due to recompilation. Subsequent executions will be much faster.
By the way if you want to just time execution as opposed to benchmarking, this is what @time is for. You could also just use Base.time_ns() directly to get the time before and after running something.
There is a bit more going on with @time than some would like.
julia> @macroexpand @time 1
quote
#= timing.jl:216 =#
while false
#= timing.jl:216 =#
end
#= timing.jl:217 =#
local var"#1#stats" = Base.gc_num()
#= timing.jl:218 =#
local var"#3#elapsedtime" = Base.time_ns()
#= timing.jl:219 =#
local var"#4#compile_elapsedtime" = Base.cumulative_compile_time_ns_before()
#= timing.jl:220 =#
local var"#2#val" = $(Expr(:tryfinally, 1, quote
var"#3#elapsedtime" = Base.time_ns() - var"#3#elapsedtime"
#= timing.jl:222 =#
var"#4#compile_elapsedtime" = Base.cumulative_compile_time_ns_after() - var"#4#compile_elapsedtime"
end))
#= timing.jl:224 =#
local var"#5#diff" = Base.GC_Diff(Base.gc_num(), var"#1#stats")
#= timing.jl:225 =#
Base.time_print(var"#3#elapsedtime", (var"#5#diff").allocd, (var"#5#diff").total_time, Base.gc_alloc_count(var"#5#diff"), var"#4#compile_elapsedtime", true)
#= timing.jl:226 =#
var"#2#val"
end