Skip to content

Commit 636a35d

Browse files
@time actually fix time report commas & add tests (#55982)
#55977 looked simple but wasn't quite right because of a bad pattern in the lock conflicts report section. So fix and add tests.
1 parent b9d9b69 commit 636a35d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

base/timing.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ function time_print(io::IO, elapsedtime, bytes=0, gctime=0, allocs=0, lock_confl
206206
print(io, length(timestr) < 10 ? (" "^(10 - length(timestr))) : "")
207207
end
208208
print(io, timestr, " seconds")
209-
parens = bytes != 0 || allocs != 0 || gctime > 0 || compile_time > 0 || lock_conflicts > 0
209+
parens = bytes != 0 || allocs != 0 || gctime > 0 || lock_conflicts > 0 || compile_time > 0
210210
parens && print(io, " (")
211211
if bytes != 0 || allocs != 0
212212
allocs, ma = prettyprint_getunits(allocs, length(_cnt_units), Int64(1000))
@@ -224,8 +224,11 @@ function time_print(io::IO, elapsedtime, bytes=0, gctime=0, allocs=0, lock_confl
224224
print(io, Ryu.writefixed(Float64(100*gctime/elapsedtime), 2), "% gc time")
225225
end
226226
if lock_conflicts > 0
227+
if bytes != 0 || allocs != 0 || gctime > 0
228+
print(io, ", ")
229+
end
227230
plural = lock_conflicts == 1 ? "" : "s"
228-
print(io, ", ", lock_conflicts, " lock conflict$plural")
231+
print(io, lock_conflicts, " lock conflict$plural")
229232
end
230233
if compile_time > 0
231234
if bytes != 0 || allocs != 0 || gctime > 0 || lock_conflicts > 0

test/misc.jl

+9
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,15 @@ let foo() = 1
360360
@test @timev foo() true
361361
end
362362

363+
# this is internal, but used for easy testing
364+
@test sprint(Base.time_print, 1e9) == " 1.000000 seconds"
365+
@test sprint(Base.time_print, 1e9, 111, 0, 222) == " 1.000000 seconds (222 allocations: 111 bytes)"
366+
@test sprint(Base.time_print, 1e9, 111, 0.5e9, 222) == " 1.000000 seconds (222 allocations: 111 bytes, 50.00% gc time)"
367+
@test sprint(Base.time_print, 1e9, 111, 0, 222, 333) == " 1.000000 seconds (222 allocations: 111 bytes, 333 lock conflicts)"
368+
@test sprint(Base.time_print, 1e9, 0, 0, 0, 333) == " 1.000000 seconds (333 lock conflicts)"
369+
@test sprint(Base.time_print, 1e9, 111, 0, 222, 333, 0.25e9) == " 1.000000 seconds (222 allocations: 111 bytes, 333 lock conflicts, 25.00% compilation time)"
370+
@test sprint(Base.time_print, 1e9, 111, 0.5e9, 222, 333, 0.25e9, 0.175e9) == " 1.000000 seconds (222 allocations: 111 bytes, 50.00% gc time, 333 lock conflicts, 25.00% compilation time: 70% of which was recompilation)"
371+
363372
# @showtime
364373
@test @showtime true
365374
let foo() = true

0 commit comments

Comments
 (0)