I am familiar with the @elapsed and @allocated functions that allow me to save as a variable either the elapsed time and allocated memory during a function run (respectively). Is there a method that will return both variables at once so they can both be saved to variables? Thanks!
1 Like
Try @timed
5 Likes
Thank you! That was so simple but I’m a beginner at Julia and couldn’t find it.
5 Likes
That’s what help forums like this are for sometimes! (Also sometimes for more complex problems) Welcome.
3 Likes
It’s definitely not a foolproof method, but the See also part of the documentation (type ? in the REPL) is often useful:
help?> @elapsed
@elapsed
A macro to evaluate an expression, discarding the resulting value, instead returning the number of seconds it took
to execute as a floating-point number.
In some cases the system will look inside the @elapsed expression and compile some of the called code before
execution of the top-level expression begins. When that happens, some compilation time will not be counted. To
include this time you can run @elapsed @eval ....
See also @time, @timev, @timed, @allocated, and @allocations.
julia> @elapsed sleep(0.3)
0.301391426
leading you to @timed
.
3 Likes