Skip to content

Commit 40844d8

Browse files
committed
better output
1 parent 4a4fc4a commit 40844d8

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,29 @@ time Julia code running in global scope!)
1111

1212
This code used to live in Julia Base in the `tic()`, `toc()`, and `toq()` functions (in base/util.jl). They were deprecated in GitHub issue [17046](https://github.com/JuliaLang/julia/issues/17046).
1313

14+
The [TimerOutputs.jl](https://github.com/KristofferC/TimerOutputs.jl) package provides tools for timing different sections of a program.
15+
1416
## Example
1517

1618
```julia
1719
julia-0.6> using TickTock
1820

1921
julia-0.6> tick()
20-
0x0000146b7dcc5c23
22+
INFO: Started timer at 2017-12-12T09:33:00.363.
2123

2224
julia-0.6> tock()
23-
2 seconds
25+
INFO: Time taken: 149.427977832
26+
INFO: 2 minutes, 29 seconds, 427 milliseconds
27+
```
28+
29+
To return the elapsed time in seconds, use `tok()`:
30+
31+
```julia
32+
julia-0.6> tick()
33+
INFO: Started timer at 2017-12-12T09:17:45.504.
34+
35+
julia-0.6> tok()
36+
287.841546621
2437
```
2538

2639
[![Build Status](https://travis-ci.org/cormullion/TickTock.jl.svg?branch=master)](https://travis-ci.org/cormullion/TickTock.jl)

appveyor.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ environment:
77

88
## uncomment the following lines to allow failures on nightly julia
99
## (tests will run but not make your overall status red)
10-
#matrix:
11-
# allow_failures:
12-
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
13-
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
10+
matrix:
11+
allow_failures:
12+
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
13+
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
1414

1515
branches:
1616
only:

src/TickTock.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Start counting.
2323
function tick()
2424
t0 = time_ns()
2525
task_local_storage(:TIMERS, (t0, get(task_local_storage(), :TIMERS, ())))
26-
return t0
26+
info("Started timer at $(now()).")
2727
end
2828

2929
"""
@@ -39,19 +39,20 @@ function tok()
3939
end
4040
t0 = timers[1]::UInt64
4141
task_local_storage(:TIMERS, timers[2])
42-
(t1-t0)/1e9 # seconds
42+
return (t1-t0)/1e9 # seconds
4343
end
4444

4545
"""
4646
tock()
4747
48-
Print the elapsed time, in suitably canonical form, since the previous `tick()`,
48+
Print the elapsed time, in canonical form, since the previous `tick()`,
4949
and then stop counting.
5050
"""
5151
function tock()
5252
t = tok()
53-
canondc = Dates.canonicalize(Dates.CompoundPeriod(Dates.Second(floor(t))))
54-
println(canondc)
53+
canondc = Dates.canonicalize(Dates.CompoundPeriod(Dates.Second(floor(t)), Dates.Millisecond(floor((t-floor(t)) * 1000))))
54+
info("Time taken: $t")
55+
info(" $canondc")
5556
end
5657

5758
end # module

test/runtests.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using TickTock
22
using Base.Test
33

4-
# write your own tests here
54
tick()
65
sleep(1)
76
@test tok() > 1.0
8-

0 commit comments

Comments
 (0)