Skip to content

Commit

Permalink
Add benchmark for update!
Browse files Browse the repository at this point in the history
  • Loading branch information
efaulhaber committed Jun 26, 2024
1 parent caa3d4e commit 03ec7ed
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions benchmarks/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include("count_neighbors.jl")
include("n_body.jl")
include("update.jl")

include("plot.jl")
43 changes: 43 additions & 0 deletions benchmarks/update.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using PointNeighbors
using BenchmarkTools

# For `perturb!`
include("../test/point_cloud.jl")

"""
benchmark_initialize(neighborhood_search, coordinates; parallel = true)
Benchmark neighborhood search initialization with the given `coordinates`.
"""
function benchmark_initialize(neighborhood_search, coordinates; parallel = true)
return @belapsed $initialize!($neighborhood_search, $coordinates, $coordinates)
end

"""
benchmark_update_alternating(neighborhood_search, coordinates; parallel = true)
A very simple benchmark for neighborhood search update, alternating between two differently
perturbed point clouds.
This is a good benchmark for incremental updates, since most particles stay in their cells.
"""
function benchmark_update_alternating(neighborhood_search, coordinates; parallel = true)
coordinates2 = copy(coordinates)
# Perturb all coordinates with a perturbation factor of `0.015`.
# This factor was tuned so that ~0.5% of the particles change their cell during an
# update in 2D and ~0.7% in 3D.
# These values are the same as the experimentally computed averages in 2D and 3D SPH
# dam break simulations. So this benchmark replicates a real-life SPH update.
perturb!(coordinates2, 0.015)

function update_alternating!(neighborhood_search, coordinates, coordinates2)
update!(neighborhood_search, coordinates, coordinates)
update!(neighborhood_search, coordinates, coordinates2)
end

result = @belapsed $update_alternating!($neighborhood_search, $coordinates,
$coordinates2)

# Return average update time
return 0.5 * result
end
8 changes: 8 additions & 0 deletions test/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@
@testset verbose=true "`benchmark_n_body`" begin
@test_nowarn_mod plot_benchmarks(benchmark_n_body, size, 2)
end

@testset verbose=true "`benchmark_initialize`" begin
@test_nowarn_mod plot_benchmarks(benchmark_initialize, size, 2)
end

@testset verbose=true "`benchmark_update_alternating`" begin
@test_nowarn_mod plot_benchmarks(benchmark_update_alternating, size, 2)
end
end
end;

0 comments on commit 03ec7ed

Please sign in to comment.