@@ -369,12 +369,13 @@ _isdef(ex) = @capture(ex, function f_(arg__) body_ end)
369369
370370"""
371371
372- @⌛ code ...
373- @⌛ function_definition() = ....
372+ @⌛ [label] code ...
373+ @⌛ [label] function_definition() = ....
374374
375- Label a section of code to be timed. The first form uses the code
376- itselfs as a label, the second uses the function name, and its the
377- body of the function which is timed.
375+ Label a section of code to be timed. If a label string is not
376+ provided, the first form uses the code itselfs as a label, the second
377+ uses the function name, and its the body of the function which is
378+ timed.
378379
379380To run the timer and print output, returning the result of the
380381calculation, use
@@ -383,16 +384,27 @@ calculation, use
383384
384385Timing uses `TimerOutputs.get_defaulttimer()`.
385386"""
386- macro ⌛ (ex)
387+ macro ⌛ (args... )
388+ if length (args)== 1
389+ label, ex = nothing , args[1 ]
390+ else
391+ label, ex = esc (args[1 ]), args[2 ]
392+ end
387393 source_str = last (splitpath (string (__source__. file)))* " :" * string (__source__. line)
388394 if _isdef (ex)
389395 sdef = splitdef (ex)
396+ if isnothing (label)
397+ label = " $(string (sdef[:name ])) (…) ($source_str )"
398+ end
390399 sdef[:body ] = quote
391- CMBLensing. @timeit $ ( " $( string (sdef[ :name ])) (…) ( $source_str ) " ) $ (sdef[:body ])
400+ CMBLensing. @timeit $ label $ (sdef[:body ])
392401 end
393402 esc (combinedef (sdef))
394403 else
395- :(@timeit $ (" $(Base. _truncate_at_width_or_chars (string (prewalk (rmlines,ex)),26 )) ($source_str )" ) $ (esc (ex)))
404+ if isnothing (label)
405+ label = " $(Base. _truncate_at_width_or_chars (string (prewalk (rmlines,ex)),26 )) ($source_str )"
406+ end
407+ :(@timeit $ label $ (esc (ex)))
396408 end
397409end
398410
0 commit comments