:@timev

@timev

This is a verbose version of the @time macro. It first prints the same information as @time, then any non-zero memory allocation counters, and then returns the value of the expression.

Examples

  1. Measure the execution time and memory allocation:

    julia> @timev begin
               a = 5 + 10;
               b = a * 2;
               println(b);
           end
    20
     0.000044 seconds (3 allocations: 144 bytes)

    This example uses @timev to measure the execution time, memory allocation, and print additional memory allocation counters. It calculates a and b and prints the value of b.

  2. Measure execution time of a function:

    julia> function factorial(n)
               if n == 0 || n == 1
                   return 1
               else
                   return n * factorial(n - 1)
               end
           end
    
    julia> result = @timev factorial(5)
    120
     0.000004 seconds (5 allocations: 176 bytes)

    In this example, @timev is used to measure the execution time and memory allocation of the factorial function when called with an argument of 5. The result is assigned to the variable result.

  3. Measure execution time of a loop:

    julia> @timev for i in 1:10
               println(i)
           end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     0.000004 seconds (200 allocations: 5.625 KiB)

    This example demonstrates the usage of @timev to measure the execution time and memory allocation of a loop that prints the numbers from 1 to 10.

Common mistake example:

julia> @timev println("Hello, world!")
ERROR: MethodError: no method matching @timev(::LineNumberNode, ::Module, ::Symbol)

In this example, @timev is not used correctly. It should be used before a code block or expression. It cannot be used directly before a function call or standalone statement. Ensure that @timev is used appropriately to measure the execution time and memory allocation of a code block or expression.

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.

*Required Field
Details

Checking you are not a robot: