tic
.. tic()
Set a timer to be read by the next call to :func:`toc` or :func:`toq`. The macro call ``@time expr`` can also be used to time evaluation.Examples
In the Julia programming language, the function tic()
Set a timer to be read by the next call to toc() or toq(). The macro call @time expr can also be used to time evaluation.
Usage examples:
-
Measure execution time of a code block:
julia> tic(); # Start the timer julia> for i in 1:1_000_000 # Code to be timed end julia> toc() # Get the elapsed time 0.006264003This example measures the execution time of a for loop by starting the timer with
tic(), running the code block, and then obtaining the elapsed time withtoc(). -
Time a specific function call:
julia> function my_function(n) # Code implementation end julia> tic(); # Start the timer julia> my_function(10_000) julia> toc() # Get the elapsed time 0.002135468Here, the
tic()andtoc()functions are used to measure the execution time of themy_functioncall. - Use
@timemacro for timing:julia> @time begin # Code to be timed endThe
@timemacro can also be used to time the evaluation of a code block. It automatically prints the elapsed time, memory allocations, and memory usage.
Please note that toq() is not a standard Julia function. If you intended to refer to another function, please provide the correct name and description.
See Also
:@time, :@timed, :@timev, now, sleep, tic, time, timedwait, Timer, time_ns, toc, toq,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.