Hello everyone,

I put up a new (unregistered) small package for timing different sections 
of code. It works similar to @time in Base but you also give the code 
section being timed a label. We can then track the total time and number of 
calls that are made to code sections with that label and pretty print it in 
the end. This feature existed in a C++ library I used to use (deal.II) and 
I missed it in Julia.

Here is a small example.

using TimerOutputs

const time_tracker = TimerOutput();

@timeit time_tracker "sleeping" sleep(1)

@timeit time_tracker "loop" for i in 1:10
   rand()
   sleep(0.1)
end

v = 0.0
for i in 1:5
    v += @timeit time_tracker "in a loop" begin
       sleep(0.1)
       rand()
    end
end

print(time_tracker)
+---------------------------------------------+------------+------------+
| Total wallclock time elapsed since start    |   3.155 s  |            |
|                                             |            |            |
| Section                         | no. calls |  wall time | % of total |
+---------------------------------------------+------------+------------+
| loop                            |         1 |   1.012 s  |       32 % |
| sleeping                        |         1 |   1.002 s  |       32 % |
| in a loop                       |         5 | 505.779 ms |       16 % |
+---------------------------------------------+------------+------------+

Feel free to comment on the package name, macro name, format of the output 
etc. 

The URL is: https://github.com/KristofferC/TimerOutputs.jl

Best regards, Kristoffer

Reply via email to