Skip to content

Commit e255608

Browse files
committed
option to turn off ⌛
1 parent 057e236 commit e255608

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/CMBLensing.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ using Memoization
3535
using NamedTupleTools: select, delete
3636
using PDMats
3737
using Pkg
38+
using Preferences
3839
using Printf
3940
using ProgressMeter
4041
using QuadGK

src/util.jl

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ expnorm(x) = exp.(x .- maximum(x))
375375
# MacroTool's is broken https://github.com/FluxML/MacroTools.jl/issues/154
376376
_isdef(ex) = @capture(ex, function f_(arg__) body_ end)
377377

378+
const _⌛_enabled = @load_preference("⌛_enabled", default=true)
379+
378380
"""
379381
380382
@⌛ [label] code ...
@@ -398,21 +400,25 @@ macro ⌛(args...)
398400
else
399401
label, ex = esc(args[1]), args[2]
400402
end
401-
source_str = last(splitpath(string(__source__.file)))*":"*string(__source__.line)
402-
if _isdef(ex)
403-
sdef = splitdef(ex)
404-
if isnothing(label)
405-
label = "$(string(sdef[:name]))(…) ($source_str)"
406-
end
407-
sdef[:body] = quote
408-
CMBLensing.@timeit $label $(sdef[:body])
403+
if _⌛_enabled
404+
source_str = last(splitpath(string(__source__.file)))*":"*string(__source__.line)
405+
if _isdef(ex)
406+
sdef = splitdef(ex)
407+
if isnothing(label)
408+
label = "$(string(sdef[:name]))(…) ($source_str)"
409+
end
410+
sdef[:body] = quote
411+
CMBLensing.@timeit $label $(sdef[:body])
412+
end
413+
esc(combinedef(sdef))
414+
else
415+
if isnothing(label)
416+
label = "$(Base._truncate_at_width_or_chars(string(prewalk(rmlines,ex)),26)) ($source_str)"
417+
end
418+
:(@timeit $label $(esc(ex)))
409419
end
410-
esc(combinedef(sdef))
411420
else
412-
if isnothing(label)
413-
label = "$(Base._truncate_at_width_or_chars(string(prewalk(rmlines,ex)),26)) ($source_str)"
414-
end
415-
:(@timeit $label $(esc(ex)))
421+
esc(ex)
416422
end
417423
end
418424

0 commit comments

Comments
 (0)