Skip to content

Commit 38984d4

Browse files
committed
Run JuliaFormatter
1 parent 433820c commit 38984d4

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 = v"1.0.0"
1616

src/execution.jl

Lines changed: 71 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ function _run(b::Benchmark, p::Parameters; verbose=false, pad="", kwargs...)
111111
return_val = trial_contents.__return_val
112112
iters = 2
113113
while (Base.time() - start_time) < params.seconds && iters params.samples
114-
params.gcsample && gcscrub()
115-
push!(trial, b.samplefunc(b.quote_vals, params))
116-
iters += 1
114+
params.gcsample && gcscrub()
115+
push!(trial, b.samplefunc(b.quote_vals, params))
116+
iters += 1
117117
end
118118
return trial, return_val
119119
end
@@ -533,67 +533,82 @@ function generate_benchmark_definition(
533533
core_body = :($(core); $(returns))
534534
end
535535
@static if isdefined(Base, :donotdelete)
536-
invocation = :(let x = $invocation
537-
Base.donotdelete(x)
538-
x
539-
end)
536+
invocation = :(
537+
let x = $invocation
538+
Base.donotdelete(x)
539+
x
540+
end
541+
)
540542
end
541543
experimental_enable_linux_perf = true # TODO: take this as input from the user
542544
# TODO: let the user actually provide these options.
543545
linux_perf_opts = LinuxPerf.parse_pstats_options([])
544-
return Core.eval(eval_module, quote
545-
@noinline $(signature_def) = begin $(core_body) end
546-
@noinline function $(samplefunc)($(Expr(:tuple, quote_vars...)), __params::$BenchmarkTools.Parameters)
547-
$(setup)
548-
__evals = __params.evals
549-
__gc_start = Base.gc_num()
550-
__start_time = time_ns()
551-
__return_val = $(invocation)
552-
for __iter in 2:__evals
553-
$(invocation)
546+
return Core.eval(
547+
eval_module,
548+
quote
549+
@noinline $(signature_def) = begin
550+
$(core_body)
554551
end
555-
__sample_time = time_ns() - __start_time
556-
__gcdiff = Base.GC_Diff(Base.gc_num(), __gc_start)
557-
$(teardown)
558-
__time = max((__sample_time / __evals) - __params.overhead, 0.001)
559-
__gctime = max((__gcdiff.total_time / __evals) - __params.overhead, 0.0)
560-
__memory = Int(Base.fld(__gcdiff.allocd, __evals))
561-
__allocs = Int(Base.fld(__gcdiff.malloc + __gcdiff.realloc +
562-
__gcdiff.poolalloc + __gcdiff.bigalloc,
563-
__evals))
564-
if $(experimental_enable_linux_perf)
565-
# Based on https://github.com/JuliaPerf/LinuxPerf.jl/blob/a7fee0ff261a5b5ce7a903af7b38d1b5c27dd931/src/LinuxPerf.jl#L1043-L1061
566-
__linux_perf_groups = BenchmarkTools.LinuxPerf.set_default_spaces(
567-
$(linux_perf_opts.events),
568-
$(linux_perf_opts.spaces),
569-
)
570-
__linux_perf_bench = BenchmarkTools.LinuxPerf.make_bench_threaded(
571-
__linux_perf_groups;
572-
threads = $(linux_perf_opts.threads),
552+
@noinline function $(samplefunc)(
553+
$(Expr(:tuple, quote_vars...)), __params::$BenchmarkTools.Parameters
554+
)
555+
$(setup)
556+
__evals = __params.evals
557+
__gc_start = Base.gc_num()
558+
__start_time = time_ns()
559+
__return_val = $(invocation)
560+
for __iter in 2:__evals
561+
$(invocation)
562+
end
563+
__sample_time = time_ns() - __start_time
564+
__gcdiff = Base.GC_Diff(Base.gc_num(), __gc_start)
565+
$(teardown)
566+
__time = max((__sample_time / __evals) - __params.overhead, 0.001)
567+
__gctime = max((__gcdiff.total_time / __evals) - __params.overhead, 0.0)
568+
__memory = Int(Base.fld(__gcdiff.allocd, __evals))
569+
__allocs = Int(
570+
Base.fld(
571+
__gcdiff.malloc +
572+
__gcdiff.realloc +
573+
__gcdiff.poolalloc +
574+
__gcdiff.bigalloc,
575+
__evals,
576+
),
573577
)
574-
BenchmarkTools.LinuxPerf.enable!(__linux_perf_bench)
575-
# We'll just run it one time.
576-
__return_val_2 = $(invocation)
577-
BenchmarkTools.LinuxPerf.disable!(__linux_perf_bench)
578-
# trick the compiler not to eliminate the code
579-
if rand() < 0
580-
__linux_perf_stats = __return_val_2
581-
else
582-
__linux_perf_stats = BenchmarkTools.LinuxPerf.Stats(__linux_perf_bench)
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), $(linux_perf_opts.spaces)
582+
)
583+
__linux_perf_bench = BenchmarkTools.LinuxPerf.make_bench_threaded(
584+
__linux_perf_groups; threads=$(linux_perf_opts.threads)
585+
)
586+
BenchmarkTools.LinuxPerf.enable!(__linux_perf_bench)
587+
# We'll just run it one time.
588+
__return_val_2 = $(invocation)
589+
BenchmarkTools.LinuxPerf.disable!(__linux_perf_bench)
590+
# trick the compiler not to eliminate the code
591+
if rand() < 0
592+
__linux_perf_stats = __return_val_2
593+
else
594+
__linux_perf_stats = BenchmarkTools.LinuxPerf.Stats(
595+
__linux_perf_bench
596+
)
597+
end
583598
end
599+
return (;
600+
__time,
601+
__gctime,
602+
__memory,
603+
__allocs,
604+
__return_val,
605+
__return_val_2,
606+
__linux_perf_stats,
607+
)
584608
end
585-
return (;
586-
__time,
587-
__gctime,
588-
__memory,
589-
__allocs,
590-
__return_val,
591-
__return_val_2,
592-
__linux_perf_stats,
593-
)
594-
end
595-
$BenchmarkTools.Benchmark($(samplefunc), $(quote_vals), $(params))
596-
end)
609+
$BenchmarkTools.Benchmark($(samplefunc), $(quote_vals), $(params))
610+
end,
611+
)
597612
end
598613

599614
######################

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)