Skip to content

Commit 28dca8a

Browse files
committed
fix #17046, deprecate tic and toc
1 parent aa79148 commit 28dca8a

File tree

11 files changed

+78
-128
lines changed

11 files changed

+78
-128
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,9 @@ Deprecated or removed
453453
`prompt_if_incorrect` argument are deprecated. Instead, prompting behavior is controlled using
454454
the `allow_prompt` keyword in the `LibGit2.CredentialPayload` constructor ([#23690]).
455455

456+
* The timing functions `tic`, `toc`, and `toq` are deprecated in favor of `@time` and `@elapsed`
457+
([#17046]).
458+
456459
Command-line option changes
457460
---------------------------
458461

base/deprecated.jl

+31
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,37 @@ end
18151815
@deprecate get_creds!(cache::CachedCredentials, credid, default) get!(cache, credid, default)
18161816
end
18171817

1818+
export tic, toq, toc
1819+
function tic()
1820+
depwarn("tic() is deprecated, use @time, @elapsed, or calls to time_ns() instead.", :tic)
1821+
t0 = time_ns()
1822+
task_local_storage(:TIMERS, (t0, get(task_local_storage(), :TIMERS, ())))
1823+
return t0
1824+
end
1825+
1826+
function _toq()
1827+
t1 = time_ns()
1828+
timers = get(task_local_storage(), :TIMERS, ())
1829+
if timers === ()
1830+
error("toc() without tic()")
1831+
end
1832+
t0 = timers[1]::UInt64
1833+
task_local_storage(:TIMERS, timers[2])
1834+
(t1-t0)/1e9
1835+
end
1836+
1837+
function toq()
1838+
depwarn("toq() is deprecated, use @elapsed or calls to time_ns() instead.", :toq)
1839+
return _toq()
1840+
end
1841+
1842+
function toc()
1843+
depwarn("toc() is deprecated, use @time, @elapsed, or calls to time_ns() instead.", :toc)
1844+
t = _toq()
1845+
println("elapsed time: ", t, " seconds")
1846+
return t
1847+
end
1848+
18181849
# END 0.7 deprecations
18191850

18201851
# BEGIN 1.0 deprecations

base/exports.jl

-3
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,8 @@ export
897897

898898
# time
899899
sleep,
900-
tic,
901900
time,
902901
time_ns,
903-
toc,
904-
toq,
905902

906903
# dates
907904
Date,

base/util.jl

-73
Original file line numberDiff line numberDiff line change
@@ -76,79 +76,6 @@ gc_time_ns() = ccall(:jl_gc_total_hrtime, UInt64, ())
7676
# total number of bytes allocated so far
7777
gc_bytes() = ccall(:jl_gc_total_bytes, Int64, ())
7878

79-
"""
80-
tic()
81-
82-
Set a timer to be read by the next call to [`toc`](@ref) or [`toq`](@ref). The
83-
macro call `@time expr` can also be used to time evaluation.
84-
85-
```julia-repl
86-
julia> tic()
87-
0x0000c45bc7abac95
88-
89-
julia> sleep(0.3)
90-
91-
julia> toc()
92-
elapsed time: 0.302745944 seconds
93-
0.302745944
94-
```
95-
"""
96-
function tic()
97-
t0 = time_ns()
98-
task_local_storage(:TIMERS, (t0, get(task_local_storage(), :TIMERS, ())))
99-
return t0
100-
end
101-
102-
"""
103-
toq()
104-
105-
Return, but do not print, the time elapsed since the last [`tic`](@ref). The
106-
macro calls `@timed expr` and `@elapsed expr` also return evaluation time.
107-
108-
```julia-repl
109-
julia> tic()
110-
0x0000c46477a9675d
111-
112-
julia> sleep(0.3)
113-
114-
julia> toq()
115-
0.302251004
116-
```
117-
"""
118-
function toq()
119-
t1 = time_ns()
120-
timers = get(task_local_storage(), :TIMERS, ())
121-
if timers === ()
122-
error("toc() without tic()")
123-
end
124-
t0 = timers[1]::UInt64
125-
task_local_storage(:TIMERS, timers[2])
126-
(t1-t0)/1e9
127-
end
128-
129-
"""
130-
toc()
131-
132-
Print and return the time elapsed since the last [`tic`](@ref). The macro call
133-
`@time expr` can also be used to time evaluation.
134-
135-
```julia-repl
136-
julia> tic()
137-
0x0000c45bc7abac95
138-
139-
julia> sleep(0.3)
140-
141-
julia> toc()
142-
elapsed time: 0.302745944 seconds
143-
0.302745944
144-
```
145-
"""
146-
function toc()
147-
t = toq()
148-
println("elapsed time: ", t, " seconds")
149-
return t
150-
end
151-
15279
# print elapsed time, return expression value
15380
const _mem_units = ["byte", "KiB", "MiB", "GiB", "TiB", "PiB"]
15481
const _cnt_units = ["", " k", " M", " G", " T", " P"]

doc/src/stdlib/base.md

-3
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,6 @@ Base.getipaddr
193193
Base.Libc.getpid
194194
Base.Libc.time()
195195
Base.time_ns
196-
Base.tic
197-
Base.toc
198-
Base.toq
199196
Base.@time
200197
Base.@timev
201198
Base.@timed

test/channels.jl

+2-3
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,8 @@ end
212212
@async begin sleep(1.0); put!(rr2, :ok) end
213213
@async begin sleep(2.0); put!(rr3, :ok) end
214214

215-
tic()
216-
timedwait(callback, Dates.Second(1))
217-
et=toq()
215+
et = @elapsed timedwait(callback, Dates.Second(1))
216+
218217
# assuming that 0.5 seconds is a good enough buffer on a typical modern CPU
219218
try
220219
@assert (et >= 1.0) && (et <= 1.5)

test/file.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ function test_file_poll(channel,interval,timeout_s)
192192
end
193193

194194
function test_timeout(tval)
195-
tic()
196-
channel = Channel(1)
197-
@async test_file_poll(channel, 10, tval)
198-
tr = take!(channel)
199-
t_elapsed = toq()
195+
t_elapsed = @elapsed begin
196+
channel = Channel(1)
197+
@async test_file_poll(channel, 10, tval)
198+
tr = take!(channel)
199+
end
200200
@test tr[1] === Base.Filesystem.StatStruct() && tr[2] === EOFError()
201201
@test tval <= t_elapsed
202202
end

test/perf/kernel/gk.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ function gk(n, myeps)
6565

6666
csum = zeros(n)
6767

68-
# tic()
6968
while(stop != 1)
7069
t=t+1
7170
iter=t
@@ -115,7 +114,7 @@ function gk(n, myeps)
115114

116115
end
117116

118-
times[KK] = 0#toc()
117+
times[KK] = 0
119118
iteration[KK] = iter
120119

121120
x = X/t

test/perf/spell/perf.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ end
7171
################ Testing code from here on ################
7272

7373
function spelltest(tests; bias=0, verbose=false)
74-
n, bad, unknown, start = 0, 0, 0, tic()
74+
n, bad, unknown, start = 0, 0, 0, time_ns()
7575
if bias > 0
7676
for target in keys(tests)
7777
NWORDS[target] = get(NWORDS, target, 1) + bias
@@ -93,7 +93,7 @@ function spelltest(tests; bias=0, verbose=false)
9393
end
9494

9595
return Dict("bad"=>bad, "n"=>n, "bias"=>bias, "pct"=>round(Int, 100. - 100. * bad/n),
96-
"unknown"=>unknown, "secs"=>toc())
96+
"unknown"=>unknown, "secs"=>(time_ns() - start)/1e9)
9797
end
9898

9999
const tests1 = Dict("access"=> "acess", "accessing"=> "accesing", "accommodation"=>

test/perf/threads/lbm3d/lbm3d.jl

+18-21
Original file line numberDiff line numberDiff line change
@@ -169,36 +169,33 @@ function lbm3d(n)
169169
numactivenodes = sum(1-BOUND)
170170

171171
@time while (ts < 4000 && (1e-10 < abs((prevavu-avu)/avu))) || ts < 100
172-
tic()
173-
# Propagate -- nearest and next-nearest neighbors
174-
for i = 2:19
175-
circshift3d1!(F, i, prop_shifts[i-1])
172+
tprop += @elapsed begin
173+
# Propagate -- nearest and next-nearest neighbors
174+
for i = 2:19
175+
circshift3d1!(F, i, prop_shifts[i-1])
176+
end
176177
end
177-
tprop = tprop + toq()
178178

179179
# Densities bouncing back at next timestep
180180
BOUNCEDBACK = F[TO_REFLECT]
181181

182-
tic()
183-
184-
# Relax; calculate equilibrium state (FEQ) with equivalent speed and density to F
185-
@threads for chunk=1:nchunk
186-
relax!(F, UX, UY, UZ, nx, ny, nz, deltaU, t1D, t2D, t3D, sSQU, chunkid, nchunk)
187-
end
188-
for o in ON
189-
UX[o] = UY[o] = UZ[o] = t1D[o] = t2D[o] = t3D[o] = sSQU[o] = 0.0
182+
trelax += @elapsed begin
183+
# Relax; calculate equilibrium state (FEQ) with equivalent speed and density to F
184+
@threads for chunk=1:nchunk
185+
relax!(F, UX, UY, UZ, nx, ny, nz, deltaU, t1D, t2D, t3D, sSQU, chunkid, nchunk)
186+
end
187+
for o in ON
188+
UX[o] = UY[o] = UZ[o] = t1D[o] = t2D[o] = t3D[o] = sSQU[o] = 0.0
189+
end
190190
end
191191

192-
trelax = trelax + toq()
193-
tic()
194-
195-
# Calculate equilibrium distribution: stationary
196-
@threads for chunk=1:nchunk
197-
calc_equi!(F, FEQ, t1D, t2D, t3D, U, UX, UY, UZ, sSQU, nx, ny, nz, omega)
192+
tequi += @elapsed begin
193+
# Calculate equilibrium distribution: stationary
194+
@threads for chunk=1:nchunk
195+
calc_equi!(F, FEQ, t1D, t2D, t3D, U, UX, UY, UZ, sSQU, nx, ny, nz, omega)
196+
end
198197
end
199198

200-
tequi = tequi + toq()
201-
202199
F[REFLECTED] = BOUNCEDBACK
203200

204201
prevavu = avu

test/pollfd.jl

+16-16
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ end
2525
function pfd_tst_reads(idx, intvl)
2626
global ready += 1
2727
wait(ready_c)
28-
tic()
29-
start_evt2 = Condition()
30-
evt2 = @async (notify(start_evt2); poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false))
31-
wait(start_evt2); yield() # make sure the async poll_fd is pumping events
32-
evt = poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false)
33-
t_elapsed = toq()
28+
t_elapsed = @elapsed begin
29+
start_evt2 = Condition()
30+
evt2 = @async (notify(start_evt2); poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false))
31+
wait(start_evt2); yield() # make sure the async poll_fd is pumping events
32+
evt = poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false)
33+
end
3434
@test !evt.timedout
3535
@test evt.readable
3636
@test !evt.writable
@@ -53,16 +53,16 @@ end
5353
function pfd_tst_timeout(idx, intvl)
5454
global ready += 1
5555
wait(ready_c)
56-
tic()
57-
start_evt2 = Condition()
58-
evt2 = @async (notify(start_evt2); poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false))
59-
wait(start_evt2); yield() # make sure the async poll_fd is pumping events
60-
evt = poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false)
61-
@test evt.timedout
62-
@test !evt.readable
63-
@test !evt.writable
64-
@test evt === wait(evt2)
65-
t_elapsed = toq()
56+
t_elapsed = @elapsed begin
57+
start_evt2 = Condition()
58+
evt2 = @async (notify(start_evt2); poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false))
59+
wait(start_evt2); yield() # make sure the async poll_fd is pumping events
60+
evt = poll_fd(pipe_fds[idx][1], intvl; readable=true, writable=false)
61+
@test evt.timedout
62+
@test !evt.readable
63+
@test !evt.writable
64+
@test evt === wait(evt2)
65+
end
6666

6767
# Disabled since these assertions fail randomly, notably on build VMs (issue #12824)
6868
# @test intvl <= t_elapsed

0 commit comments

Comments
 (0)