Skip to content

Commit 9b86ecf

Browse files
committed
Run JuliaFormatter
1 parent d1a69eb commit 9b86ecf

File tree

3 files changed

+78
-61
lines changed

3 files changed

+78
-61
lines changed

src/BenchmarkTools.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ using UUIDs: uuid4
99
using Printf
1010
using Profile
1111

12-
import LinuxPerf
13-
import Random
12+
using LinuxPerf: LinuxPerf
13+
using Random: Random
1414

1515
const BENCHMARKTOOLS_VERSION = if VERSION >= v"1.9"
1616
pkgversion(BenchmarkTools)

src/execution.jl

Lines changed: 71 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ function _run(b::Benchmark, p::Parameters; verbose=false, pad="", warmup=true, k
121121
return_val = trial_contents.__return_val
122122
iters = 2
123123
while (Base.time() - start_time) < params.seconds && iters params.samples
124-
params.gcsample && gcscrub()
125-
push!(trial, b.samplefunc(b.quote_vals, params))
126-
iters += 1
124+
params.gcsample && gcscrub()
125+
push!(trial, b.samplefunc(b.quote_vals, params))
126+
iters += 1
127127
end
128128
return trial, return_val
129129
end
@@ -547,67 +547,82 @@ function generate_benchmark_definition(
547547
core_body = :($(core); $(returns))
548548
end
549549
@static if isdefined(Base, :donotdelete)
550-
invocation = :(let x = $invocation
551-
Base.donotdelete(x)
552-
x
553-
end)
550+
invocation = :(
551+
let x = $invocation
552+
Base.donotdelete(x)
553+
x
554+
end
555+
)
554556
end
555557
experimental_enable_linux_perf = true # TODO: take this as input from the user
556558
# TODO: let the user actually provide these options.
557559
linux_perf_opts = LinuxPerf.parse_pstats_options([])
558-
return Core.eval(eval_module, quote
559-
@noinline $(signature_def) = begin $(core_body) end
560-
@noinline function $(samplefunc)($(Expr(:tuple, quote_vars...)), __params::$BenchmarkTools.Parameters)
561-
$(setup)
562-
__evals = __params.evals
563-
__gc_start = Base.gc_num()
564-
__start_time = time_ns()
565-
__return_val = $(invocation)
566-
for __iter in 2:__evals
567-
$(invocation)
560+
return Core.eval(
561+
eval_module,
562+
quote
563+
@noinline $(signature_def) = begin
564+
$(core_body)
568565
end
569-
__sample_time = time_ns() - __start_time
570-
__gcdiff = Base.GC_Diff(Base.gc_num(), __gc_start)
571-
$(teardown)
572-
__time = max((__sample_time / __evals) - __params.overhead, 0.001)
573-
__gctime = max((__gcdiff.total_time / __evals) - __params.overhead, 0.0)
574-
__memory = Int(Base.fld(__gcdiff.allocd, __evals))
575-
__allocs = Int(Base.fld(__gcdiff.malloc + __gcdiff.realloc +
576-
__gcdiff.poolalloc + __gcdiff.bigalloc,
577-
__evals))
578-
if $(experimental_enable_linux_perf)
579-
# Based on https://github.com/JuliaPerf/LinuxPerf.jl/blob/a7fee0ff261a5b5ce7a903af7b38d1b5c27dd931/src/LinuxPerf.jl#L1043-L1061
580-
__linux_perf_groups = BenchmarkTools.LinuxPerf.set_default_spaces(
581-
$(linux_perf_opts.events),
582-
$(linux_perf_opts.spaces),
583-
)
584-
__linux_perf_bench = BenchmarkTools.LinuxPerf.make_bench_threaded(
585-
__linux_perf_groups;
586-
threads = $(linux_perf_opts.threads),
566+
@noinline function $(samplefunc)(
567+
$(Expr(:tuple, quote_vars...)), __params::$BenchmarkTools.Parameters
568+
)
569+
$(setup)
570+
__evals = __params.evals
571+
__gc_start = Base.gc_num()
572+
__start_time = time_ns()
573+
__return_val = $(invocation)
574+
for __iter in 2:__evals
575+
$(invocation)
576+
end
577+
__sample_time = time_ns() - __start_time
578+
__gcdiff = Base.GC_Diff(Base.gc_num(), __gc_start)
579+
$(teardown)
580+
__time = max((__sample_time / __evals) - __params.overhead, 0.001)
581+
__gctime = max((__gcdiff.total_time / __evals) - __params.overhead, 0.0)
582+
__memory = Int(Base.fld(__gcdiff.allocd, __evals))
583+
__allocs = Int(
584+
Base.fld(
585+
__gcdiff.malloc +
586+
__gcdiff.realloc +
587+
__gcdiff.poolalloc +
588+
__gcdiff.bigalloc,
589+
__evals,
590+
),
587591
)
588-
BenchmarkTools.LinuxPerf.enable!(__linux_perf_bench)
589-
# We'll just run it one time.
590-
__return_val_2 = $(invocation)
591-
BenchmarkTools.LinuxPerf.disable!(__linux_perf_bench)
592-
# trick the compiler not to eliminate the code
593-
if rand() < 0
594-
__linux_perf_stats = __return_val_2
595-
else
596-
__linux_perf_stats = BenchmarkTools.LinuxPerf.Stats(__linux_perf_bench)
592+
if $(experimental_enable_linux_perf)
593+
# Based on https://github.com/JuliaPerf/LinuxPerf.jl/blob/a7fee0ff261a5b5ce7a903af7b38d1b5c27dd931/src/LinuxPerf.jl#L1043-L1061
594+
__linux_perf_groups = BenchmarkTools.LinuxPerf.set_default_spaces(
595+
$(linux_perf_opts.events), $(linux_perf_opts.spaces)
596+
)
597+
__linux_perf_bench = BenchmarkTools.LinuxPerf.make_bench_threaded(
598+
__linux_perf_groups; threads=$(linux_perf_opts.threads)
599+
)
600+
BenchmarkTools.LinuxPerf.enable!(__linux_perf_bench)
601+
# We'll just run it one time.
602+
__return_val_2 = $(invocation)
603+
BenchmarkTools.LinuxPerf.disable!(__linux_perf_bench)
604+
# trick the compiler not to eliminate the code
605+
if rand() < 0
606+
__linux_perf_stats = __return_val_2
607+
else
608+
__linux_perf_stats = BenchmarkTools.LinuxPerf.Stats(
609+
__linux_perf_bench
610+
)
611+
end
597612
end
613+
return (;
614+
__time,
615+
__gctime,
616+
__memory,
617+
__allocs,
618+
__return_val,
619+
__return_val_2,
620+
__linux_perf_stats,
621+
)
598622
end
599-
return (;
600-
__time,
601-
__gctime,
602-
__memory,
603-
__allocs,
604-
__return_val,
605-
__return_val_2,
606-
__linux_perf_stats,
607-
)
608-
end
609-
$BenchmarkTools.Benchmark($(samplefunc), $(quote_vals), $(params))
610-
end)
623+
$BenchmarkTools.Benchmark($(samplefunc), $(quote_vals), $(params))
624+
end,
625+
)
611626
end
612627

613628
######################

src/trials.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ mutable struct Trial
88
gctimes::Vector{Float64}
99
memory::Int
1010
allocs::Int
11-
linux_perf_stats::Union{LinuxPerf.Stats, Nothing}
11+
linux_perf_stats::Union{LinuxPerf.Stats,Nothing}
1212
end
1313

14-
Trial(params::Parameters) = Trial(params, Float64[], Float64[], typemax(Int), typemax(Int), nothing)
14+
function Trial(params::Parameters)
15+
return Trial(params, Float64[], Float64[], typemax(Int), typemax(Int), nothing)
16+
end
1517

1618
function Base.:(==)(a::Trial, b::Trial)
1719
return a.params == b.params &&
@@ -38,7 +40,7 @@ const TrialContents = NamedTuple{(
3840
function Base.push!(t::Trial, trial_contents::TrialContents)
3941
time = trial_contents.__time
4042
gctime = trial_contents.__gctime
41-
memory = trial_contents.__memory
43+
memory = trial_contents.__memory
4244
allocs = trial_contents.__allocs
4345
push!(t.times, time)
4446
push!(t.gctimes, gctime)

0 commit comments

Comments
 (0)