Skip to content

Commit 1729c43

Browse files
committed
added doc strings
1 parent 51ea449 commit 1729c43

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# TickTock
22

3+
This module provides `tick()`, `tock()`, and `tok()` functions.
4+
5+
They're similar to the `tic()`, `toc()`, and `toq()` functions that you might find in MATLAB and
6+
similar software.
7+
8+
## Example
9+
10+
```julia
11+
julia-0.6> using TickTock
12+
13+
julia-0.6> tick()
14+
0x0000146b7dcc5c23
15+
16+
julia-0.6> tock()
17+
2 seconds
18+
```
19+
320
[![Build Status](https://travis-ci.org/cormullion/TickTock.jl.svg?branch=master)](https://travis-ci.org/cormullion/TickTock.jl)
421

522
[![Coverage Status](https://coveralls.io/repos/cormullion/TickTock.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/cormullion/TickTock.jl?branch=master)

src/TickTock.jl

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,51 @@
1+
"""
2+
This module provides `tick()`, `tock()`, and `tok()` functions.
3+
4+
They're similar to the `tic()`, `toc()`, and `toq()` functions that you might find in MATLAB and
5+
similar software.
6+
"""
7+
18
module TickTock
29

3-
export tick, tock
10+
export tick, tock, tok
11+
12+
"""
13+
tick()
414
15+
Start counting.
16+
"""
517
function tick()
618
t0 = time_ns()
719
task_local_storage(:TIMERS, (t0, get(task_local_storage(), :TIMERS, ())))
820
return t0
921
end
1022

11-
function toqk()
23+
"""
24+
tok()
25+
26+
Return the time since the previous `tick()`, in seconds, and then stop counting.
27+
"""
28+
function tok()
1229
t1 = time_ns()
1330
timers = get(task_local_storage(), :TIMERS, ())
1431
if timers === ()
15-
error("You tock()ed before you tick()ed...")
32+
error("You must first use `tick()`.")
1633
end
1734
t0 = timers[1]::UInt64
1835
task_local_storage(:TIMERS, timers[2])
19-
(t1-t0)/1e9
36+
(t1-t0)/1e9 # seconds
2037
end
2138

39+
"""
40+
tock()
41+
42+
Print the elapsed time, in suitably canonical form, since the previous `tick()`,
43+
and then stop counting.
44+
"""
2245
function tock()
23-
t = toqk()
24-
dc = Dates.canonicalize(Dates.CompoundPeriod(now() - t))
25-
println(dc)
26-
return dc
46+
t = tok()
47+
canondc = Dates.canonicalize(Dates.CompoundPeriod(Dates.Second(floor(t))))
48+
println(canondc)
2749
end
2850

2951
end # module

test/runtests.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ using TickTock
22
using Base.Test
33

44
# write your own tests here
5-
@test 1 == 2
5+
tick()
6+
sleep(1)
7+
@test tok() > 1.0
8+

0 commit comments

Comments
 (0)