Skip to content

Commit

Permalink
factor out code for printing @time results.
Browse files Browse the repository at this point in the history
This would normally not be a big deal, but we're emitting this code.
  • Loading branch information
StefanKarpinski committed Jun 28, 2014
1 parent e928eda commit 45c4952
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
12 changes: 7 additions & 5 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ include("version.jl")
include("datafmt.jl")
importall .DataFmt
include("deepcopy.jl")
include("util.jl")
include("interactiveutil.jl")
include("replutil.jl")
include("test.jl")
Expand All @@ -216,6 +215,13 @@ include("REPLCompletions.jl")
include("REPL.jl")
include("client.jl")

# (s)printf macros
include("printf.jl")
importall .Printf

# misc useful functions & macros
include("util.jl")

# sparse matrices and linear algebra
include("sparse.jl")
importall .SparseMatrix
Expand All @@ -234,10 +240,6 @@ include("fftw.jl")
include("dsp.jl")
importall .DSP

# (s)printf macros
include("printf.jl")
importall .Printf

# system information
include("sysinfo.jl")
import .Sys.CPU_CORES
Expand Down
17 changes: 10 additions & 7 deletions base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ function toc()
end

# print elapsed time, return expression value

function time_print(t, b, g)
if 0 < g
@printf("elapsed time: %s seconds (%d bytes allocated, %.2f%% gc time)\n", t/1e9, b, 100*g/t)
else
@printf("elapsed time: %s seconds (%d bytes allocated)\n", t/1e9, b)
end
end

macro time(ex)
quote
local b0 = gc_bytes()
Expand All @@ -45,13 +54,7 @@ macro time(ex)
local g1 = gc_time_ns()
local t1 = time_ns()
local b1 = gc_bytes()
if g1 > g0
@printf("elapsed time: %s seconds (%d bytes allocated, %.2f%% gc time)\n",
(t1-t0)/1e9, b1-b0, 100*(g1-g0)/(t1-t0))
else
@printf("elapsed time: %s seconds (%d bytes allocated)\n",
(t1-t0)/1e9, b1-b0)
end
time_print(t1-t0, b1-b0, g1-g0)
val
end
end
Expand Down

0 comments on commit 45c4952

Please sign in to comment.