Alternative to tic() and toc()

What’s an easy-to-type alternative to tic() and toc(), for timing a sequence of commands (or anything else, really), which are disappearing soon?

Sort of like this:

julia-0.6> t = now()
2017-12-11T16:11:31.365 
...
...

julia-0.6> Dates.canonicalize(Dates.CompoundPeriod(now() - t))
29 seconds, 800 milliseconds

only easier to type.

The proper way would be to use BenchmarkTools.jl and @btime.
If you are only interested in one off runtime @time and its siblings are useful.

3 Likes

But I don’t want to benchmark Julia code, I want an easy way to time how long things take. tic() and toc() are easy to type and remember…

You can wrap in a begin-end block:

@time begin
    #code
end

Or use something like GitHub - KristofferC/TimerOutputs.jl: Formatted output of timed sections in Julia for timing several things and pretty print it.

3 Likes

Someone could add the old tic / toc / toq functions from Base to the MatlabCompat package.

5 Likes

Thanks, Stefan. In fact, I don’t need anything else from MATLAB so I’m happy with a separate package for my own purposes. :slight_smile: