Created
April 5, 2017 17:13
-
-
Save sglyon/3e4c4ac0ac5728a510fd371cd418f51a to your computer and use it in GitHub Desktop.
showtime macros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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