Skip to content

Commit

Permalink
Convert message in timing macros before printing (#55122)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Jul 16, 2024
1 parent d02bfeb commit 742e7d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions base/timing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ macro time(msg, ex)
quote
local ret = @timed $(esc(ex))
local _msg = $(esc(msg))
time_print(stdout, ret.time*1e9, ret.gcstats.allocd, ret.gcstats.total_time, gc_alloc_count(ret.gcstats), ret.lock_conflicts, ret.compile_time*1e9, ret.recompile_time*1e9, true; msg=_msg)
local _msg_str = _msg === nothing ? _msg : string(_msg)
time_print(stdout, ret.time*1e9, ret.gcstats.allocd, ret.gcstats.total_time, gc_alloc_count(ret.gcstats), ret.lock_conflicts, ret.compile_time*1e9, ret.recompile_time*1e9, true; msg=_msg_str)
ret.value
end
end
Expand Down Expand Up @@ -387,7 +388,8 @@ macro timev(msg, ex)
quote
local ret = @timed $(esc(ex))
local _msg = $(esc(msg))
timev_print(ret.time*1e9, ret.gcstats, ret.lock_conflicts, (ret.compile_time*1e9, ret.recompile_time*1e9); msg=_msg)
local _msg_str = _msg === nothing ? _msg : string(_msg)
timev_print(ret.time*1e9, ret.gcstats, ret.lock_conflicts, (ret.compile_time*1e9, ret.recompile_time*1e9); msg=_msg_str)
ret.value
end
end
Expand Down
9 changes: 9 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -321,25 +321,34 @@ v11801, t11801 = @timed sin(1)
@test names(@__MODULE__, all = true) == names_before_timing

redirect_stdout(devnull) do # suppress time prints

# Accepted @time argument formats
@test @time true
@test @time "message" true
@test @time 1 true
let msg = "message"
@test @time msg true
end
let foo() = "message"
@test @time foo() true
end
let foo() = 1
@test @time foo() true
end

# Accepted @timev argument formats
@test @timev true
@test @timev "message" true
@test @timev 1 true
let msg = "message"
@test @timev msg true
end
let foo() = "message"
@test @timev foo() true
end
let foo() = 1
@test @timev foo() true
end

# @showtime
@test @showtime true
Expand Down

0 comments on commit 742e7d9

Please sign in to comment.