`@time` output is a tiny bit noisy

Quick question, is there a mini-package that defines something like the following:

using Printf

macro time′(ex)
    # prime time
    # (saner name, e.g: htime, for 'human' time)
        t0 = time()
        Δt = time() - t0
        @printf("%.2G seconds\n", Δt)

Most of the times that I use @time I don’t have to know about memory allocations or more than 2 significant digits of time duration.

I wager I’m not alone?
Given that, I wondered if it would be an idea to add something like this to Base. An anti-@timev (time verbose)
Has there been previous discussion on this that I’ve missed?

1 Like

To explain a bit further: quick-n-dirty analyses I write often consist of multiple steps, and I print feedback between these steps on what is happening and how long the last step took

Goals are to know: is it computing, or is it hanging / did it crash? At what step are we know? How long did that take?

Thanks! @btime is just as noisy, and possible repeats work, right?
I’d seen TimerOutputs.jl but it looked a bit overkill for quick scripts; but I’ll give it a try, it might be exactly what I need

Edit: No, my impression was right. It doesn’t seem to give live feedback during the running of the expression, and takes more code than @time
Looks like a great package but not what I was looking for

I’ve gotten a lot of mileage out of GitHub - timholy/ProgressMeter.jl: Progress meter for long-running computations though for similar use cases

julia> @timed(sin(1.0)).time

Doesn’t @ellapsed does that (except for the units)?


@elapsed doesn’t print any output, though, which seems to be the point of the question. The nice thing about @time is that it times, prints the timing information, and doesn’t change the returned value (i.e., @time 1 + 1 will return 2, whereas @elapsed 1 + 1 will return the duration of the operation), all with minimal typing.

1 Like