Skip to content

Instantly share code, notes, and snippets.

@sglyon
Created April 5, 2017 17:13
Show Gist options
  • Save sglyon/3e4c4ac0ac5728a510fd371cd418f51a to your computer and use it in GitHub Desktop.
Save sglyon/3e4c4ac0ac5728a510fd371cd418f51a to your computer and use it in GitHub Desktop.
showtime macros
macro showtime(ex)
blk = Expr(:block)
push!(blk.args, :(println($(sprint(Base.show_unquoted,ex)*" = "),
repr(begin value=$(esc(ex)) end))))
push!(blk.args, :value)
quote
local stats = Base.gc_num()
local elapsedtime = Base.time_ns()
$blk
elapsedtime = Base.time_ns() - elapsedtime
local diff = Base.GC_Diff(Base.gc_num(), stats)
Base.time_print(elapsedtime, diff.allocd, diff.total_time, Base.gc_alloc_count(diff))
value
end
end
macro printtime(ex)
blk = Expr(:block)
push!(blk.args, :(println($(sprint(Base.show_unquoted,ex)*" = "),
"...")))
push!(blk.args, :(value = $(esc(ex))))
quote
local stats = Base.gc_num()
local elapsedtime = Base.time_ns()
$blk
elapsedtime = Base.time_ns() - elapsedtime
local diff = Base.GC_Diff(Base.gc_num(), stats)
Base.time_print(elapsedtime, diff.allocd, diff.total_time, Base.gc_alloc_count(diff))
value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment