diff --git a/Project.toml b/Project.toml index c863a6a..6c6f196 100644 --- a/Project.toml +++ b/Project.toml @@ -4,11 +4,12 @@ version = "0.5.9" [deps] ExprTools = "e2ba6199-217a-4e67-a87a-7c52f15ade04" +FastClosures = "9aa1b823-49e4-5ca5-8b0f-3971ec8bab6a" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" [compat] -julia = "1" ExprTools = "0.1.0" +julia = "1" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/src/TimerOutput.jl b/src/TimerOutput.jl index ac1187e..0de6ade 100644 --- a/src/TimerOutput.jl +++ b/src/TimerOutput.jl @@ -237,12 +237,14 @@ function timer_expr_func(m::Module, is_debug::Bool, to, expr::Expr, label=nothin label === nothing && (label = string(def[:name])) + @gensym closure def[:body] = if is_debug + closure_ex = FastClosures.wrap_closure(m, :( + () -> $(def[:body]) + )) quote - @inline function inner() - $(def[:body]) - end - $(_timer_expr(m, is_debug, to, label, :(inner()))) + $closure = $closure_ex + $(_timer_expr(m, is_debug, to, label, :($closure()))) end else _timer_expr(m, is_debug, to, label, def[:body]) diff --git a/src/TimerOutputs.jl b/src/TimerOutputs.jl index 4979733..83350af 100644 --- a/src/TimerOutputs.jl +++ b/src/TimerOutputs.jl @@ -2,6 +2,8 @@ module TimerOutputs using ExprTools +using FastClosures + import Base: show, time_ns export TimerOutput, @timeit, @timeit_debug, reset_timer!, print_timer, timeit, enable_timer!, disable_timer!, @notimeit