diff --git a/base/sysimg.jl b/base/sysimg.jl index ae47e46074af3..a6df4d94e7cd5 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -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") @@ -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 @@ -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 diff --git a/base/util.jl b/base/util.jl index 4f5e12c8ef6e1..e6835b0cc668a 100644 --- a/base/util.jl +++ b/base/util.jl @@ -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() @@ -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