# Real time timer?

**URL:** <https://discourse.julialang.org/t/real-time-timer/59407>\
**Category:** New to Julia\
**Created:** [April 16, 2021, 12:30pm UTC](https://discourse.julialang.org/t/real-time-timer/59407 "2021-04-16T12:30:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ribeiro](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@Ribeiro](https://discourse.julialang.org/u/Ribeiro)\
**Post date:** [April 16, 2021, 12:30pm UTC](https://discourse.julialang.org/t/real-time-timer/59407/1 "2021-04-16T12:30:58Z")

</div>

Hello, all.  
I was wondering if there was a macro out there similar to @time, but that shows the timer update in real time. Anyone know one?  
The use case is that I’ve got some pretty expensive functions and it would be good to be able to glimpse at the screen and figure out that one of them hasn’t progressed in a long time. So if the terminal could show real elapsed time while the timer is running, that would be ideal.  
The alternative is to print the time when the function started and then look at the clock, but that’s not as nice.  
Thanks a lot!

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [April 16, 2021, 12:56pm UTC](https://discourse.julialang.org/t/real-time-timer/59407/2 "2021-04-16T12:56:58Z")

</div>

I once made a package that did a bit of timing… It might still work:

```julia
julia> using TickTock

julia> tick()
[ Info: started timer at: 2021-04-16T13:54:20.094

julia> tick()
[ Info: started timer at: 2021-04-16T13:54:22.932

julia> tick()
[ Info: started timer at: 2021-04-16T13:54:25.362

julia> TickTock.showtimes()
3 [ Info: 2.895372181s: 2 seconds, 895 milliseconds
2 [ Info: 5.325055601s: 5 seconds, 325 milliseconds
1 [ Info: 8.179692675s: 8 seconds, 179 milliseconds

julia> TickTock.showtimes()
3 [ Info: 5.505053393s: 5 seconds, 505 milliseconds
2 [ Info: 7.934736813s: 7 seconds, 934 milliseconds
1 [ Info: 10.789373887s: 10 seconds, 789 milliseconds

```

Hopefully something better will come along soon. 😹

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [April 16, 2021, 1:28pm UTC](https://discourse.julialang.org/t/real-time-timer/59407/3 "2021-04-16T13:28:24Z")

</div>

There’s [https://github.com/timholy/ProgressMeter.jl](https://github.com/timholy/ProgressMeter.jl) which has a `@showprogress` macro which can make progress bars in the terminal like

```julia
Computing initial pass...53%|███████████████████████████ | ETA: 0:09:02

```

It’s pretty nice!

There is also [https://github.com/JunoLab/ProgressLogging.jl](https://github.com/JunoLab/ProgressLogging.jl) which one can use in conjugation with an editor like VSCode or a terminal logger like [https://github.com/c42f/TerminalLoggers.jl](https://github.com/c42f/TerminalLoggers.jl).

---

<div class="post-metadata">

**Author:** ![Ribeiro](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@Ribeiro](https://discourse.julialang.org/u/Ribeiro)\
**Post date:** [April 16, 2021, 2:15pm UTC](https://discourse.julialang.org/t/real-time-timer/59407/4 "2021-04-16T14:15:49Z")

</div>

@cormullion Yeah, displaying the start time was the easy alternative (and I am currently doing it with `Dates.now()`, but I was wondering if there was a nicer solution.  
@ericphanson Those are pretty cool, but I was looking for something decoupled from a for loop. One of the functions I call which often hangs is a linear system solver, which comes from a package and depends on residuals, so it’s not a clear `for i in 1:10` type of thing.  
If anyone knows a package that shows something like a running timer, that’d be great.  
Thanks again!

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [April 16, 2021, 2:19pm UTC](https://discourse.julialang.org/t/real-time-timer/59407/5 "2021-04-16T14:19:48Z")

</div>

Both those packages support lots of custom control. As an example from the ProgressMeters README,

```julia
function my_long_running_function(filenames::Array)
    n = length(filenames)
    p = Progress(n, 1) # minimum update interval: 1 second
    for f in filenames
        # Here's where you do all the hard, slow work
        next!(p)
    end
end

```

Here, `next!(p)` could be called anywhere, e.g. from inside a recursive function. There’s a lot more options too, I encourage you to check out the docs.
