Julia: Deprecate tic and toc

Created on 21 Jun 2016  Â·  14Comments  Â·  Source: JuliaLang/julia

I suggest that we should deprecate tic and toc and explain that @elapsed or one of the @time family should be used instead.

decision deprecation

Most helpful comment

Oftentimes, in my MATLAB code, I use tic and toc to allow me to have the code output the time since a certain point in the code, in order to be able to easily keep track of run time mid-run.

Sure, it can be done in julia using time() and storing the "tic" time and then subtracting it from the time where I want to "toc", but tic/toc makes it much cleaner.

So rather than deprecating tic and toc, I'd actually like to see them extended slightly. Right now, you can only have one toc/toq per tic. It would be nice if you could reuse the existing tic until a new tic is set, perhaps with "tok()"? (for "toc keep", much as toq is "toc quiet")

All 14 comments

-1 Deprecation of a warm welcome to matlab users?

How about rather add a tip to toc reccomending @time and @elapsed in Julia as superior timing facilities?

julia> tic();
julia> toc();
elapest time: 2.123456 seconds
    You should also try the @time and @elapsed macros for timing in Julia

The macros can't replace tic and toc in all usage, e.g. tic(); using Compat; toc(). Maybe

julia> @time using Compat                                                                                                  
ERROR: unsupported or misplaced expression using

could be fixed though?

@ivarne They are especially a problem for MATLAB users who use them incorrectly do run benchmarks in the global scope. :-)

Anyway, MATLABisms should go to MATLAB.jl, the only argument for keeping tic and toc would be that they make sense in Julia itself (which @tkelman's comment seems to indicate).

PS: @nalimilan I don't think you meant MATLAB.jl (Source)

The MATLAB.jl package provides an interface for using MATLABâ„¢ from the Julia language. You cannot use MATLAB.jl without having purchased and installed a copy of MATLABâ„¢ from MathWorks. This package is available free of charge and in no way replaces or alters any functionality of MathWorks's MATLAB product.

I agree that tic and toc isn't ideal for use in Julia. The problem is that many users don't read the manual, and someone with matlab experience will try tic\toc before looking. That is a great time to give the answer they expect, and suggest better benchmarking methods. (A UndefVarError is not a nice experience)

Another option will naturally be to override printing of UndefVarError for tic and toc in the REPL to give proper guidance to the better methods.

@ivarne Sorry, I meant MatlabCompat.jl.

Coming from Python, I love tic() and toc() a lot. Easy and intuitive!

@ivarne: This is a very good suggestion, but could be applied to various other functions as well. Thus it might be good to provide a more general framework here, where a list of "common" functions from other languages is parsed.

Personally, I would not see an urgent need to remove these two particular functions. But this is quite subjective of course.

Oftentimes, in my MATLAB code, I use tic and toc to allow me to have the code output the time since a certain point in the code, in order to be able to easily keep track of run time mid-run.

Sure, it can be done in julia using time() and storing the "tic" time and then subtracting it from the time where I want to "toc", but tic/toc makes it much cleaner.

So rather than deprecating tic and toc, I'd actually like to see them extended slightly. Right now, you can only have one toc/toq per tic. It would be nice if you could reuse the existing tic until a new tic is set, perhaps with "tok()"? (for "toc keep", much as toq is "toc quiet")

From triage: Let's deprecate these methods and put them into MatlabCompat for people who are used to them from MATLAB. They are unintuitive for people who don't know them and the fact that they have global state makes them pretty much useless anywhere but the REPL.

Right – the global state is a disaster in combination with threading.

the fact that they have global state

just fwiw, they don't have global state, and have no issues at all being used with threading.

Ah, it's task-local?

Ah, yeah, that's true. The original implementation used a global array – I was thinking of that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ararslan picture ararslan  Â·  3Comments

tkoolen picture tkoolen  Â·  3Comments

Keno picture Keno  Â·  3Comments

manor picture manor  Â·  3Comments

helgee picture helgee  Â·  3Comments