Skip to content

Commit ea06cfa

Browse files
committed
add cputime and realtime and cleanup
1 parent 94a1e73 commit ea06cfa

10 files changed

+159
-111
lines changed

src/BenchmarkTools.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ if VERSION >= v"0.7.0-DEV.3052"
1010
using Printf
1111
end
1212

13-
const BENCHMARKTOOLS_VERSION = v"0.2.2"
13+
const BENCHMARKTOOLS_VERSION = v"0.3.0"
14+
15+
##########
16+
# Timers #
17+
##########
18+
19+
include("timers/timers.jl")
1420

1521
##############
1622
# Parameters #
@@ -26,7 +32,9 @@ export loadparams!
2632

2733
include("trials.jl")
2834

29-
export gctime,
35+
export realtime,
36+
cputime,
37+
gctime,
3038
memory,
3139
allocs,
3240
params,

src/execution.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,18 +314,18 @@ function generate_benchmark_definition(eval_module, out_vars, setup_vars, core,
314314
$(setup)
315315
__evals = __params.evals
316316
__gc_start = Base.gc_num()
317-
__start_realtime = Timers.realtime()
318-
__start_cputime = Timers.cputime()
317+
__start_realtime = BenchmarkTools.Timers.realtime()
318+
__start_cputime = BenchmarkTools.Timers.cputime()
319319
__return_val = $(invocation)
320320
for __iter in 2:__evals
321321
$(invocation)
322322
end
323-
__sample_realtime = Timers.realtime() - __start_realtime
324-
__sample_cputime = Timers.cputime() - __start_cputime
323+
__sample_realtime = $BenchmarkTools.Timers.realtime() - __start_realtime
324+
__sample_cputime = $BenchmarkTools.Timers.cputime() - __start_cputime
325325
__gcdiff = Base.GC_Diff(Base.gc_num(), __gc_start)
326326
$(teardown)
327-
__realtime = max((__realsample_time / __evals) - __params.overhead, 0.001)
328-
__cputime = max((__cpusample_time / __evals) - __params.overhead, 0.001)
327+
__realtime = max((__sample_realtime / __evals) - __params.overhead, 0.001)
328+
__cputime = max((__sample_cputime / __evals) - __params.overhead, 0.001)
329329
__gctime = max((__gcdiff.total_time / __evals) - __params.overhead, 0.0)
330330
__memory = Int(fld(__gcdiff.allocd, __evals))
331331
__allocs = Int(fld(__gcdiff.malloc + __gcdiff.realloc +
@@ -382,7 +382,7 @@ is the *minimum* elapsed time measured during the benchmark.
382382
macro belapsed(args...)
383383
b = Expr(:macrocall, Symbol("@benchmark"), map(esc, args)...)
384384
return esc(quote
385-
$BenchmarkTools.time($BenchmarkTools.minimum($BenchmarkTools.@benchmark $(args...)))/1e9
385+
$BenchmarkTools.realtime($BenchmarkTools.minimum($BenchmarkTools.@benchmark $(args...)))/1e9
386386
end)
387387
end
388388

@@ -412,7 +412,7 @@ macro btime(args...)
412412
$trialmin = $BenchmarkTools.minimum($trial)
413413
$trialallocs = $BenchmarkTools.allocs($trialmin)
414414
println(" ",
415-
$BenchmarkTools.prettytime($BenchmarkTools.time($trialmin)),
415+
$BenchmarkTools.prettytime($BenchmarkTools.realtime($trialmin)),
416416
" (", $trialallocs , " allocation",
417417
$trialallocs == 1 ? "" : "s", ": ",
418418
$BenchmarkTools.prettymemory($BenchmarkTools.memory($trialmin)), ")")

src/groups.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ Base.median(group::BenchmarkGroup) = mapvals(median, group)
8181
Base.min(groups::BenchmarkGroup...) = mapvals(min, groups...)
8282
Base.max(groups::BenchmarkGroup...) = mapvals(max, groups...)
8383

84-
Base.time(group::BenchmarkGroup) = mapvals(time, group)
84+
import Base: time
85+
@deprecate time(group::BenchmarkGroup) realtime(group)
86+
realtime(group::BenchmarkGroup) = mapvals(realtime, group)
87+
cputime(group::BenchmarkGroup) = mapvals(cputime, group)
8588
gctime(group::BenchmarkGroup) = mapvals(gctime, group)
8689
memory(group::BenchmarkGroup) = mapvals(memory, group)
8790
allocs(group::BenchmarkGroup) = mapvals(allocs, group)

src/serialization.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if VERSION >= v"0.7.0-DEV.2437"
2-
using Base.Meta.parse
2+
using Base.Meta: parse
33
end
44

55
const VERSIONS = Dict("Julia" => string(VERSION),

src/timers/timers.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Based upon https://github.com/google/benchmark
33
=#
44

55
module Timers
6+
import Compat
67

78
"""
89
realtime()
@@ -26,13 +27,13 @@ function _applever()
2627
return VersionNumber(readchomp(`sw_vers -productVersion`))
2728
end
2829

29-
if is_apple() && _applever() < v"10.12.0"
30+
if Compat.Sys.isapple() && _applever() < v"10.12.0"
3031
include("darwin.jl")
31-
elseif is_unix()
32+
elseif Compat.Sys.isunix()
3233
include("unix.jl")
33-
elseif is_windows()
34+
elseif Compat.Sys.iswindows()
3435
include("windows.jl")
3536
else
36-
error("$(Sys.Kernel) is not supported please file an issue")
37+
error("$(Sys.KERNEL) is not supported please file an issue")
3738
end
3839
end # module

src/timers/unix.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ maketime(ts) = ts.tv_sec * 1e9 + ts.tv_nsec
77

88
# From bits/times.h on a Linux system
99
# Check if those are the same on BSD
10-
if is_linux()
10+
if Compat.Sys.islinux()
1111
const CLOCK_MONOTONIC = Cint(1)
1212
const CLOCK_PROCESS_CPUTIME_ID = Cint(2)
1313
elseif Sys.KERNEL == :FreeBSD # atleast on FreeBSD 11.1
1414
const CLOCK_MONOTONIC = Cint(4)
1515
const CLOCK_PROCESS_CPUTIME_ID = Cint(14)
16-
elseif is_apple() # Version 10.12 required
16+
elseif Compat.Sys.isapple() # Version 10.12 required
1717
const CLOCK_MONOTONIC = Cint(6)
1818
const CLOCK_PROCESS_CPUTIME_ID = Cint(12)
1919
else
2020
error("""
21-
BenchmarkTools doesn't currently support your system.
21+
BenchmarkTools doesn't currently support your operating system.
2222
Please file an issue, your kernel is $(Sys.KERNEL)
2323
""")
2424
end

0 commit comments

Comments
 (0)