Skip to content

Commit

Permalink
add cputime and realtime and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Jan 18, 2018
1 parent 94a1e73 commit ea06cfa
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 111 deletions.
12 changes: 10 additions & 2 deletions src/BenchmarkTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ if VERSION >= v"0.7.0-DEV.3052"
using Printf
end

const BENCHMARKTOOLS_VERSION = v"0.2.2"
const BENCHMARKTOOLS_VERSION = v"0.3.0"

##########
# Timers #
##########

include("timers/timers.jl")

##############
# Parameters #
Expand All @@ -26,7 +32,9 @@ export loadparams!

include("trials.jl")

export gctime,
export realtime,
cputime,
gctime,
memory,
allocs,
params,
Expand Down
16 changes: 8 additions & 8 deletions src/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,18 +314,18 @@ function generate_benchmark_definition(eval_module, out_vars, setup_vars, core,
$(setup)
__evals = __params.evals
__gc_start = Base.gc_num()
__start_realtime = Timers.realtime()
__start_cputime = Timers.cputime()
__start_realtime = BenchmarkTools.Timers.realtime()
__start_cputime = BenchmarkTools.Timers.cputime()
__return_val = $(invocation)
for __iter in 2:__evals
$(invocation)
end
__sample_realtime = Timers.realtime() - __start_realtime
__sample_cputime = Timers.cputime() - __start_cputime
__sample_realtime = $BenchmarkTools.Timers.realtime() - __start_realtime
__sample_cputime = $BenchmarkTools.Timers.cputime() - __start_cputime
__gcdiff = Base.GC_Diff(Base.gc_num(), __gc_start)
$(teardown)
__realtime = max((__realsample_time / __evals) - __params.overhead, 0.001)
__cputime = max((__cpusample_time / __evals) - __params.overhead, 0.001)
__realtime = max((__sample_realtime / __evals) - __params.overhead, 0.001)
__cputime = max((__sample_cputime / __evals) - __params.overhead, 0.001)
__gctime = max((__gcdiff.total_time / __evals) - __params.overhead, 0.0)
__memory = Int(fld(__gcdiff.allocd, __evals))
__allocs = Int(fld(__gcdiff.malloc + __gcdiff.realloc +
Expand Down Expand Up @@ -382,7 +382,7 @@ is the *minimum* elapsed time measured during the benchmark.
macro belapsed(args...)
b = Expr(:macrocall, Symbol("@benchmark"), map(esc, args)...)
return esc(quote
$BenchmarkTools.time($BenchmarkTools.minimum($BenchmarkTools.@benchmark $(args...)))/1e9
$BenchmarkTools.realtime($BenchmarkTools.minimum($BenchmarkTools.@benchmark $(args...)))/1e9
end)
end

Expand Down Expand Up @@ -412,7 +412,7 @@ macro btime(args...)
$trialmin = $BenchmarkTools.minimum($trial)
$trialallocs = $BenchmarkTools.allocs($trialmin)
println(" ",
$BenchmarkTools.prettytime($BenchmarkTools.time($trialmin)),
$BenchmarkTools.prettytime($BenchmarkTools.realtime($trialmin)),
" (", $trialallocs , " allocation",
$trialallocs == 1 ? "" : "s", ": ",
$BenchmarkTools.prettymemory($BenchmarkTools.memory($trialmin)), ")")
Expand Down
5 changes: 4 additions & 1 deletion src/groups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ Base.median(group::BenchmarkGroup) = mapvals(median, group)
Base.min(groups::BenchmarkGroup...) = mapvals(min, groups...)
Base.max(groups::BenchmarkGroup...) = mapvals(max, groups...)

Base.time(group::BenchmarkGroup) = mapvals(time, group)
import Base: time
@deprecate time(group::BenchmarkGroup) realtime(group)
realtime(group::BenchmarkGroup) = mapvals(realtime, group)
cputime(group::BenchmarkGroup) = mapvals(cputime, group)
gctime(group::BenchmarkGroup) = mapvals(gctime, group)
memory(group::BenchmarkGroup) = mapvals(memory, group)
allocs(group::BenchmarkGroup) = mapvals(allocs, group)
Expand Down
2 changes: 1 addition & 1 deletion src/serialization.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if VERSION >= v"0.7.0-DEV.2437"
using Base.Meta.parse
using Base.Meta: parse
end

const VERSIONS = Dict("Julia" => string(VERSION),
Expand Down
9 changes: 5 additions & 4 deletions src/timers/timers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Based upon https://github.com/google/benchmark
=#

module Timers
import Compat

"""
realtime()
Expand All @@ -26,13 +27,13 @@ function _applever()
return VersionNumber(readchomp(`sw_vers -productVersion`))
end

if is_apple() && _applever() < v"10.12.0"
if Compat.Sys.isapple() && _applever() < v"10.12.0"
include("darwin.jl")
elseif is_unix()
elseif Compat.Sys.isunix()
include("unix.jl")
elseif is_windows()
elseif Compat.Sys.iswindows()
include("windows.jl")
else
error("$(Sys.Kernel) is not supported please file an issue")
error("$(Sys.KERNEL) is not supported please file an issue")
end
end # module
6 changes: 3 additions & 3 deletions src/timers/unix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ maketime(ts) = ts.tv_sec * 1e9 + ts.tv_nsec

# From bits/times.h on a Linux system
# Check if those are the same on BSD
if is_linux()
if Compat.Sys.islinux()
const CLOCK_MONOTONIC = Cint(1)
const CLOCK_PROCESS_CPUTIME_ID = Cint(2)
elseif Sys.KERNEL == :FreeBSD # atleast on FreeBSD 11.1
const CLOCK_MONOTONIC = Cint(4)
const CLOCK_PROCESS_CPUTIME_ID = Cint(14)
elseif is_apple() # Version 10.12 required
elseif Compat.Sys.isapple() # Version 10.12 required
const CLOCK_MONOTONIC = Cint(6)
const CLOCK_PROCESS_CPUTIME_ID = Cint(12)
else
error("""
BenchmarkTools doesn't currently support your system.
BenchmarkTools doesn't currently support your operating system.
Please file an issue, your kernel is $(Sys.KERNEL)
""")
end
Expand Down
Loading

0 comments on commit ea06cfa

Please sign in to comment.