Skip to content

Commit 678b4a2

Browse files
committed
Update the benchmarks
Also add an analysis & plotting function
1 parent f0be3f9 commit 678b4a2

File tree

2 files changed

+83
-21
lines changed

2 files changed

+83
-21
lines changed

perf/benchmarks.jl

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ end
1515
@nexprs $N d->inds_d = inds[d]
1616
s = zero(eltype(itp))
1717
@inbounds @nloops $N i d->inds_d begin
18-
s += @nref($N, itp, i)
18+
s += @ncall($N, itp, i)
1919
end
2020
s
2121
end
2222
end
2323

2424
function sumvalues_indices(itp)
25-
inds = indices(itp)
25+
inds = axes(itp)
2626
n = Int(round(10^(3/ndims(itp))))
27-
ntuple(d->collect(linspace(first(inds[d])+0.001, last(inds[d])-0.001, n)), ndims(itp))
27+
ntuple(d->collect(range(first(inds[d])+0.001, stop=last(inds[d])-0.001, length=n)), ndims(itp))
2828
end
2929

30-
strip_prefix(str) = replace(str, "Interpolations.", "")
30+
strip_prefix(str) = replace(str, "Interpolations."=>"")
3131
benchstr(::Type{T}) where {T<:Interpolations.GridType} = strip_prefix(string(T))
3232

3333
benchstr(::Type{Constant}) = "Constant()"
@@ -49,25 +49,23 @@ for A in (collect(Float64, 1:3),
4949
# Constant & Linear
5050
for D in (Constant, Linear)
5151
gstr = groupstr(D)
52-
for GT in (OnGrid, OnCell)
53-
Ac = copy(A)
54-
idstr = string(ndims(A), "d_", benchstr(D), '_', benchstr(GT))
55-
suite["bsplines"][gstr][string(idstr, "_construct")] =
56-
@benchmarkable interpolate($Ac, BSpline($D()), $GT())
57-
itp = interpolate(copy(A), BSpline(D()), GT())
58-
inds = sumvalues_indices(itp)
59-
suite["bsplines"][gstr][string(idstr, "_use")] =
60-
@benchmarkable sumvalues($itp, $inds)
61-
end
52+
Ac = copy(A)
53+
idstr = string(ndims(A), "d_", benchstr(D), '_', benchstr(OnGrid))
54+
suite["bsplines"][gstr][string(idstr, "_construct")] =
55+
@benchmarkable interpolate($Ac, BSpline($D()))
56+
itp = interpolate(copy(A), BSpline(D()))
57+
inds = sumvalues_indices(itp)
58+
suite["bsplines"][gstr][string(idstr, "_use")] =
59+
@benchmarkable sumvalues($itp, $inds)
6260
end
6361
# Quadratic
6462
gstr = groupstr(Quadratic)
6563
for BC in (Flat,Line,Free,Periodic,Reflect,Natural), GT in (OnGrid, OnCell)
6664
Ac = copy(A)
6765
idstr = string(ndims(A), "d_", benchstr(Quadratic{BC}), '_', benchstr(GT))
6866
suite["bsplines"][gstr][string(idstr, "_construct")] =
69-
@benchmarkable interpolate($Ac, BSpline(Quadratic($BC())), $GT())
70-
itp = interpolate(copy(A), BSpline(Quadratic(BC())), GT())
67+
@benchmarkable interpolate($Ac, BSpline(Quadratic($BC($GT()))))
68+
itp = interpolate(copy(A), BSpline(Quadratic(BC(GT()))))
7169
inds = sumvalues_indices(itp)
7270
suite["bsplines"][gstr][string(idstr, "_use")] =
7371
@benchmarkable sumvalues($itp, $inds)
@@ -76,8 +74,8 @@ for A in (collect(Float64, 1:3),
7674
Ac = copy(A)
7775
idstr = string(ndims(A), "d_", benchstr(Quadratic{BC}), '_', benchstr(OnCell))
7876
suite["bsplines"][gstr][string(idstr, "_construct")] =
79-
@benchmarkable interpolate!($Ac, BSpline(Quadratic($BC())), OnCell())
80-
itp = interpolate!(copy(A), BSpline(Quadratic(BC())), OnCell())
77+
@benchmarkable interpolate!($Ac, BSpline(Quadratic($BC(OnCell()))))
78+
itp = interpolate!(copy(A), BSpline(Quadratic(BC(OnCell()))))
8179
inds = sumvalues_indices(itp)
8280
suite["bsplines"][gstr][string(idstr, "_use")] =
8381
@benchmarkable sumvalues($itp, $inds)
@@ -88,8 +86,8 @@ for A in (collect(Float64, 1:3),
8886
Ac = copy(A)
8987
idstr = string(ndims(A), "d_", benchstr(Cubic{BC}), '_', benchstr(GT))
9088
suite["bsplines"][gstr][string(idstr, "_construct")] =
91-
@benchmarkable interpolate($Ac, BSpline(Cubic($BC())), $GT())
92-
itp = interpolate(copy(A), BSpline(Cubic(BC())), GT())
89+
@benchmarkable interpolate($Ac, BSpline(Cubic($BC($GT()))))
90+
itp = interpolate(copy(A), BSpline(Cubic(BC(GT()))))
9391
inds = sumvalues_indices(itp)
9492
suite["bsplines"][gstr][string(idstr, "_use")] =
9593
@benchmarkable sumvalues($itp, $inds)
@@ -101,7 +99,11 @@ paramspath = joinpath(dirname(@__FILE__), "params.json")
10199
if isfile(paramspath)
102100
loadparams!(suite, BenchmarkTools.load(paramspath)[1], :evals);
103101
else
104-
info("Tuning suite (this may take a while)")
102+
@info "Tuning suite (this may take a while)"
105103
tune!(suite)
106104
BenchmarkTools.save(paramspath, params(suite));
107105
end
106+
107+
# To run the benchmarks:
108+
# results = run(suite, verbose = true, seconds = 1)
109+
# BenchmarkTools.save(filename, results)

perf/compare_benchmarks.jl

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# NOTE: create symlinks called "results_old.json" and "results_new.json" in this directory
2+
# to the results files you want to compare
3+
4+
using BenchmarkTools, PyPlot, Unitful
5+
6+
const tref = 1000
7+
8+
function xycmp(results_old, results_new, filterstrs...)
9+
x, y = Float64[], Float64[]
10+
for (k, v) in results_new
11+
passes = true
12+
for str in filterstrs
13+
passes &= occursin(str, k)
14+
end
15+
passes || continue
16+
if haskey(results_old, k)
17+
push!(x, minimum(results_old[k]).time/tref)
18+
push!(y, minimum(v).time/tref)
19+
end
20+
end
21+
x, y
22+
end
23+
24+
function plotcmp(results_old, results_new, keys, filterstrs...)
25+
for key in keys
26+
results_old = results_old[key]
27+
results_new = results_new[key]
28+
end
29+
x, y = xycmp(results_old, results_new, filterstrs...)
30+
maxxy = max(maximum(x), maximum(y))
31+
scatter(x, y)
32+
plot([0, maxxy], [0, maxxy], "--")
33+
# title(string(keys, filterstrs))
34+
title(string(keys))
35+
end
36+
37+
function plotcmppanels(results_old, results_new, keys, filterstrs...)
38+
nrows = ceil(Int, sqrt(length(keys)))
39+
ncols = ceil(Int, length(keys)/nrows)
40+
figure()
41+
for k = 1:length(keys)
42+
subplot(nrows, ncols, k)
43+
plotcmp(results_old, results_new, keys[k], filterstrs...)
44+
end
45+
suptitle(string(filterstrs))
46+
end
47+
48+
results_old = BenchmarkTools.load("results_old.json")[1]
49+
results_new = BenchmarkTools.load("results_new.json")[1]
50+
51+
results_old = results_old["bsplines"]
52+
results_new = results_new["bsplines"]
53+
54+
for filt in (("use",), ("construct",))
55+
# for keys in (("constant",), ("linear",), ("quadratic",), ("cubic",))
56+
# plotcmp(results_old, results_new, keys, filt...)
57+
# end
58+
keys = (("constant",), ("linear",), ("quadratic",), ("cubic",))
59+
plotcmppanels(results_old, results_new, keys, filt...)
60+
end

0 commit comments

Comments
 (0)