Skip to content

Commit 6a00b17

Browse files
IanButterworthKristofferC
authored andcommitted
@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. (cherry picked from commit 636a35d)
1 parent 4f81618 commit 6a00b17

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
@@ -180,7 +180,7 @@ function time_print(io::IO, elapsedtime, bytes=0, gctime=0, allocs=0, lock_confl
180180
print(io, length(timestr) < 10 ? (" "^(10 - length(timestr))) : "")
181181
end
182182
print(io, timestr, " seconds")
183-
parens = bytes != 0 || allocs != 0 || gctime > 0 || compile_time > 0 || lock_conflicts > 0
183+
parens = bytes != 0 || allocs != 0 || gctime > 0 || lock_conflicts > 0 || compile_time > 0
184184
parens && print(io, " (")
185185
if bytes != 0 || allocs != 0
186186
allocs, ma = prettyprint_getunits(allocs, length(_cnt_units), Int64(1000))
@@ -198,8 +198,11 @@ function time_print(io::IO, elapsedtime, bytes=0, gctime=0, allocs=0, lock_confl
198198
print(io, Ryu.writefixed(Float64(100*gctime/elapsedtime), 2), "% gc time")
199199
end
200200
if lock_conflicts > 0
201+
if bytes != 0 || allocs != 0 || gctime > 0
202+
print(io, ", ")
203+
end
201204
plural = lock_conflicts == 1 ? "" : "s"
202-
print(io, ", ", lock_conflicts, " lock conflict$plural")
205+
print(io, lock_conflicts, " lock conflict$plural")
203206
end
204207
if compile_time > 0
205208
if bytes != 0 || allocs != 0 || gctime > 0 || lock_conflicts > 0

test/misc.jl

+9
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,15 @@ let foo() = "message"
339339
@test @timev foo() true
340340
end
341341

342+
# this is internal, but used for easy testing
343+
@test sprint(Base.time_print, 1e9) == " 1.000000 seconds"
344+
@test sprint(Base.time_print, 1e9, 111, 0, 222) == " 1.000000 seconds (222 allocations: 111 bytes)"
345+
@test sprint(Base.time_print, 1e9, 111, 0.5e9, 222) == " 1.000000 seconds (222 allocations: 111 bytes, 50.00% gc time)"
346+
@test sprint(Base.time_print, 1e9, 111, 0, 222, 333) == " 1.000000 seconds (222 allocations: 111 bytes, 333 lock conflicts)"
347+
@test sprint(Base.time_print, 1e9, 0, 0, 0, 333) == " 1.000000 seconds (333 lock conflicts)"
348+
@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)"
349+
@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)"
350+
342351
# @showtime
343352
@test @showtime true
344353
let foo() = true

0 commit comments

Comments
 (0)