Skip to content

Commit 0996139

Browse files
committed
Fix bugs so @benchmark works
1 parent 6466d98 commit 0996139

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/execution.jl

Lines changed: 8 additions & 8 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)[1:(end - 1)]...)
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
@@ -563,23 +563,23 @@ function generate_benchmark_definition(
563563
__evals))
564564
if $(experimental_enable_linux_perf)
565565
# Based on https://github.com/JuliaPerf/LinuxPerf.jl/blob/a7fee0ff261a5b5ce7a903af7b38d1b5c27dd931/src/LinuxPerf.jl#L1043-L1061
566-
__linux_perf_groups = LinuxPerf.set_default_spaces(
566+
__linux_perf_groups = BenchmarkTools.LinuxPerf.set_default_spaces(
567567
$(linux_perf_opts.events),
568568
$(linux_perf_opts.spaces),
569569
)
570-
__linux_perf_bench = LinuxPerf.make_bench_threaded(
570+
__linux_perf_bench = BenchmarkTools.LinuxPerf.make_bench_threaded(
571571
__linux_perf_groups;
572572
threads = $(linux_perf_opts.threads),
573573
)
574-
LinuxPerf.enable!(__linux_perf_bench)
574+
BenchmarkTools.LinuxPerf.enable!(__linux_perf_bench)
575575
# We'll just run it one time.
576576
__return_val_2 = $(invocation)
577-
LinuxPerf.disable!(__linux_perf_bench)
577+
BenchmarkTools.LinuxPerf.disable!(__linux_perf_bench)
578578
# trick the compiler not to eliminate the code
579579
if rand() < 0
580580
__linux_perf_stats = __return_val_2
581581
else
582-
__linux_perf_stats = LinuxPerf.Stats(__linux_perf_bench)
582+
__linux_perf_stats = BenchmarkTools.LinuxPerf.Stats(__linux_perf_bench)
583583
end
584584
end
585585
return (;

src/trials.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mutable struct Trial
1111
linux_perf_stats::Union{LinuxPerf.Stats, Nothing}
1212
end
1313

14-
Trial(params::Parameters) = Trial(params, Float64[], Float64[], typemax(Int), typemax(Int))
14+
Trial(params::Parameters) = Trial(params, Float64[], Float64[], typemax(Int), typemax(Int), nothing)
1515

1616
function Base.:(==)(a::Trial, b::Trial)
1717
return a.params == b.params &&
@@ -31,6 +31,7 @@ const TrialContents = NamedTuple{(
3131
:__memory,
3232
:__allocs,
3333
:__return_val,
34+
:__return_val_2,
3435
:__linux_perf_stats,
3536
)}
3637

@@ -43,7 +44,7 @@ function Base.push!(t::Trial, trial_contents::TrialContents)
4344
push!(t.gctimes, gctime)
4445
memory < t.memory && (t.memory = memory)
4546
allocs < t.allocs && (t.allocs = allocs)
46-
trial.linux_perf_stats = trial_contents.__linux_perf_stats
47+
t.linux_perf_stats = trial_contents.__linux_perf_stats
4748
return t
4849
end
4950

0 commit comments

Comments
 (0)