Skip to content

Commit

Permalink
Add plotting capability for benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
asinghvi17 committed Apr 25, 2024
1 parent f6ed67c commit ea28b9f
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions benchmarks/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,58 @@ _reprocess_r_polygons!(race)
_reprocess_r_polygons!(wards)
_reprocess_r_polygons!(wardsClipped)

# Run benchmark
racy_wards = interpolate(Direct(), wards, race; features = (:TOTAL_E,))

# Run benchmark in Julia
using Chairmarks
using ArealInterpolation
@be interpolate(Direct(), $wards, $race; features = $((:TOTAL_E,))) seconds=3
@be interpolate(Direct(), $wards, $race; features = $((:TOTAL_E,)), threaded = false) seconds=3
multi_threaded_benchmark = @be interpolate(Direct(), $wards, $race; features = $((:TOTAL_E,))) seconds=3
single_threaded_benchmark = @be interpolate(Direct(), $wards, $race; features = $((:TOTAL_E,)), threaded = false) seconds=3
# Multithreaded 9ms, single-threaded 43ms, R 65ms median timings!!

racy_wards = interpolate(Direct(), wards, race; features = (:TOTAL_E,))
# # Plotting
# Get R benchmark
r_benchmark = RData.load(joinpath(@__DIR__, "benchmarks.RData"))["res"]
r_benchmark.expr.pool.levels .= (x -> contains(x, "st_interpolate") ? "R (sf)" : "R (areal)").(r_benchmark.expr.pool.levels)
r_benchmark
using DataFrames, Statistics
r_gdf = groupby(r_benchmark, :expr)
r_stats = [(mean(r_gdf[key].time) / 10^6, std(r_gdf[key].time) / 10^6, string(key.expr)) for key in keys(r_gdf)]

xs = [1, 2, 3, 4]
ys = [Statistics.mean(multi_threaded_benchmark).time * 10^3, Statistics.mean(single_threaded_benchmark).time * 10^3, first.(r_stats)...]
errs = [Statistics.std(multi_threaded_benchmark).time * 10^3, Statistics.std(single_threaded_benchmark).time * 10^3, getindex.(r_stats, 2)...]
xlabels = ["Multithreaded", "Single-threaded", last.(r_stats)...]

using CairoMakie, MakieThemes
with_theme(MakieThemes.bbc()) do
scatter(
[1, 2, 3],
[9, 43, 65];
f, a, p = scatter(
xs, ys;
axis = (;
title = "Benchmarking regular interpolation",
subtitle = "On the St. Louis wards dataset",
subtitle = Makie.rich("On the St. Louis wards dataset from ", rich("areal"; font = :mono)),
ylabel = "Median time to execute (ms)",
xticks = (1:3, ["Multithreaded", "Single-threaded", "R (areal)"]),
xticks = (xs, xlabels),
xticksvisible = true,
xticklabelsvisible = true,
ytickformat = values -> string.(round.((Int,), values)) .* " ms",
yticks = Makie.WilkinsonTicks(7; k_min = 3, k_max = 10),
),
figure = (;
fonts = (;
regular = "Helvetica",
bold = "Helvetica Neue Bold",
italic = "Helvetica Oblique",
mono = "Fira Mono",
),
)
)
errorbars!(
a,
xs,
ys,
errs;
color = (:gray, 0.4)
)
f
end

0 comments on commit ea28b9f

Please sign in to comment.