@@ -139,10 +139,14 @@ function format_bytes(bytes; binary=true) # also used by InteractiveUtils
139
139
end
140
140
end
141
141
142
- function time_print (io:: IO , elapsedtime, bytes= 0 , gctime= 0 , allocs= 0 , compile_time= 0 , recompile_time= 0 , newline= false , _lpad = true )
142
+ function time_print (io:: IO , elapsedtime, bytes= 0 , gctime= 0 , allocs= 0 , compile_time= 0 , recompile_time= 0 , newline= false ; msg :: Union{String,Nothing} = nothing )
143
143
timestr = Ryu. writefixed (Float64 (elapsedtime/ 1e9 ), 6 )
144
144
str = sprint () do io
145
- _lpad && print (io, length (timestr) < 10 ? (" " ^ (10 - length (timestr))) : " " )
145
+ if msg isa String
146
+ print (io, msg, " : " )
147
+ else
148
+ print (io, length (timestr) < 10 ? (" " ^ (10 - length (timestr))) : " " )
149
+ end
146
150
print (io, timestr, " seconds" )
147
151
parens = bytes != 0 || allocs != 0 || gctime > 0 || compile_time > 0
148
152
parens && print (io, " (" )
@@ -179,11 +183,11 @@ function time_print(io::IO, elapsedtime, bytes=0, gctime=0, allocs=0, compile_ti
179
183
nothing
180
184
end
181
185
182
- function timev_print (elapsedtime, diff:: GC_Diff , compile_times, _lpad )
186
+ function timev_print (elapsedtime, diff:: GC_Diff , compile_times; msg :: Union{String,Nothing} = nothing )
183
187
allocs = gc_alloc_count (diff)
184
188
compile_time = first (compile_times)
185
189
recompile_time = last (compile_times)
186
- time_print (stdout , elapsedtime, diff. allocd, diff. total_time, allocs, compile_time, recompile_time, true , _lpad )
190
+ time_print (stdout , elapsedtime, diff. allocd, diff. total_time, allocs, compile_time, recompile_time, true ; msg )
187
191
padded_nonzero_print (elapsedtime, " elapsed time (ns)" )
188
192
padded_nonzero_print (diff. total_time, " gc time (ns)" )
189
193
padded_nonzero_print (diff. allocd, " bytes allocated" )
@@ -282,9 +286,7 @@ macro time(msg, ex)
282
286
)
283
287
local diff = GC_Diff (gc_num (), stats)
284
288
local _msg = $ (esc (msg))
285
- local has_msg = ! isnothing (_msg)
286
- has_msg && print (_msg, " : " )
287
- time_print (stdout , elapsedtime, diff. allocd, diff. total_time, gc_alloc_count (diff), first (compile_elapsedtimes), last (compile_elapsedtimes), true , ! has_msg)
289
+ time_print (stdout , elapsedtime, diff. allocd, diff. total_time, gc_alloc_count (diff), first (compile_elapsedtimes), last (compile_elapsedtimes), true ; msg= _msg)
288
290
val
289
291
end
290
292
end
@@ -366,9 +368,7 @@ macro timev(msg, ex)
366
368
)
367
369
local diff = GC_Diff (gc_num (), stats)
368
370
local _msg = $ (esc (msg))
369
- local has_msg = ! isnothing (_msg)
370
- has_msg && print (_msg, " : " )
371
- timev_print (elapsedtime, diff, compile_elapsedtimes, ! has_msg)
371
+ timev_print (elapsedtime, diff, compile_elapsedtimes; msg= _msg)
372
372
val
373
373
end
374
374
end
0 commit comments