|
1 | 1 | """ |
2 | 2 | This module provides `tick()`, `tock()`, and `tok()` functions. |
3 | 3 |
|
4 | | -They're similar to the `tic()`, `toc()`, and `toq()` functions that you might find in MATLAB |
5 | | -and similar software. |
| 4 | +- `tick()` ` start a new timer and start counting |
| 5 | +- `tock()` ` stop counting, show total elapsed time in canonical form |
| 6 | +- `tok()` ` stop counting, show and return total elapsed time in seconds |
| 7 | +- `peektimer() ` continue counting, show and return elapsed seconds so far |
| 8 | +- `laptimer() ` continue counting, show elapsed time so far in canonical form |
6 | 9 |
|
7 | 10 | Don't use these for timing code execution! Julia provides much better facilities for |
8 | 11 | measuring performance, ranging from the `@time` and `@elapsed` macros to packages such as |
9 | | -[BenchmarkTools.jl](https://github.com/JuliaCI/BenchmarkTools.jl). (And remember, don't |
10 | | -time Julia code running in global scope!) |
11 | | -
|
12 | | -This code used to live in Julia Base as the `tic()`, `toc()`, and `toq()` functions |
13 | | -(in base/util.jl). They were deprecated in GitHub issue [17046](https://github.com/JuliaLang/julia/issues/17046). |
| 12 | +[BenchmarkTools.jl](https://github.com/JuliaCI/BenchmarkTools.jl). |
14 | 13 | """ |
15 | 14 | module TickTock |
16 | 15 |
|
17 | 16 | export tick, tock, tok, peektimer, laptimer |
18 | 17 |
|
19 | 18 | if VERSION > v"0.7.0-" |
20 | | - using Dates # for now() :( |
| 19 | + using Dates # for now() |
21 | 20 | end |
22 | 21 |
|
23 | 22 | """ |
24 | 23 | tick() |
25 | 24 |
|
26 | | -Start counting. The other functions are: |
| 25 | +Start a timer. |
27 | 26 |
|
28 | | -- `tock()` ` stop counting, show total elapsed time in canonical form |
29 | | -- `tok()` ` stop counting, return seconds |
30 | | -- `peektimer() ` continue counting, return elapsed seconds |
31 | | -- `laptimer() ` continue counting, show total elapsed time in canonical form |
| 27 | +Other functions: `tock()` (stop counting and show canonical), `tok()` (stop |
| 28 | +counting and return seconds), `peektimer()` (continue counting, return elapsed |
| 29 | +seconds), and `laptimer()` (continue counting, show canonical) |
32 | 30 | """ |
33 | 31 | function tick() |
34 | 32 | t0 = time_ns() |
|
60 | 58 | """ |
61 | 59 | peektimer() |
62 | 60 |
|
63 | | -Return the current elapsed seconds counted by the most recent timer, without stopping it. |
| 61 | +Return the elapsed seconds counted by the most recent timer, without stopping it. |
64 | 62 | """ |
65 | 63 | function peektimer() |
66 | 64 | t1 = time_ns() |
|
75 | 73 | """ |
76 | 74 | tok() |
77 | 75 |
|
78 | | -Return the current elapsed seconds counted by the most recent timer, then stop counting. |
| 76 | +Return the elapsed seconds counted by the most recent timer, then stop counting. |
79 | 77 | """ |
80 | 78 | function tok() |
81 | 79 | timers = get(task_local_storage(), :TIMERS, ()) |
|
112 | 110 | """ |
113 | 111 | laptimer() |
114 | 112 |
|
115 | | -Print the current elapsed time, in canonical form, since the previous `tick()`, |
116 | | -and continue counting. |
| 113 | +Print the elapsed time, in canonical form, of the most recent timer, and continue counting. |
117 | 114 | """ |
118 | 115 | laptimer() = showtimes(canonical=true) |
119 | 116 |
|
|
0 commit comments