June 2019
Intermediate to advanced
218 pages
5h 19m
English
Whenever you care about the performance of your code, the @time macro will end up being one of your most widely used commands on the Julia prompt. Built into the base Julia runtime, this macro wraps the provided expression to calculate and print the elapsed time while running it. It also measures and prints the amount of memory allocated while running that code.
julia> @time sqrt(rand(1000)); 0.000023 seconds (8 allocations: 15.969 KB)
Any kind of Julia expressions can be wrapped by the @time macro. Usually, it is a function call as above, but it could be any other valid expression:
julia> @time for i in 1:1000 x = sin.(rand(1000)) end 0.023210 seconds (2.00 k allocations: 15.503 MiB, 38.35% gc time)
Read now
Unlock full access