Alternative to tic() and toc()

question

#1

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.


#2

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

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…


#4

You can wrap in a begin-end block:

@time begin
    #code
end

Or use something like https://github.com/KristofferC/TimerOutputs.jl for timing several things and pretty print it.


#5

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


#6

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: