# Alternative to tic() and toc()

**URL:** <https://discourse.julialang.org/t/alternative-to-tic-and-toc/7693>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 11, 2017, 4:13pm UTC](https://discourse.julialang.org/t/alternative-to-tic-and-toc/7693 "2017-12-11T16:13:32Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [December 11, 2017, 4:13pm UTC](https://discourse.julialang.org/t/alternative-to-tic-and-toc/7693/1 "2017-12-11T16:13:32Z")

</div>

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
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.

---

<div class="post-metadata">

**Author:** ![vchuravy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vchuravy/32/8_2.png) [@vchuravy](https://discourse.julialang.org/u/vchuravy)\
**Post date:** [December 11, 2017, 4:17pm UTC](https://discourse.julialang.org/t/alternative-to-tic-and-toc/7693/2 "2017-12-11T16:17:32Z")

</div>

The proper way would be to use [`BenchmarkTools.jl`](https://github.com/JuliaCI/BenchmarkTools.jl) and `@btime`.  
If you are only interested in one off runtime `@time` and its siblings are useful.

---

<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:** [December 11, 2017, 4:23pm UTC](https://discourse.julialang.org/t/alternative-to-tic-and-toc/7693/3 "2017-12-11T16:23:57Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [December 11, 2017, 4:26pm UTC](https://discourse.julialang.org/t/alternative-to-tic-and-toc/7693/4 "2017-12-11T16:26:30Z")

</div>

You can wrap in a `begin-end` block:

```julia
@time begin
    #code
end

```

Or use something like [GitHub - KristofferC/TimerOutputs.jl: Formatted output of timed sections in Julia](https://github.com/KristofferC/TimerOutputs.jl) for timing several things and pretty print it.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [December 11, 2017, 4:54pm UTC](https://discourse.julialang.org/t/alternative-to-tic-and-toc/7693/5 "2017-12-11T16:54:59Z")

</div>

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

---

<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:** [December 11, 2017, 6:51pm UTC](https://discourse.julialang.org/t/alternative-to-tic-and-toc/7693/6 "2017-12-11T18:51:54Z")

</div>

Thanks, Stefan. In fact, I don’t need anything else from MATLAB so I’m happy with a [separate package](https://github.com/cormullion/TickTock) for my own purposes. 🙂
