Skip to content

Commit

Permalink
Create Benchmarks (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar committed Apr 26, 2024
1 parent 37f65e2 commit 8ec88c4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
using PrecompileTools

@setup_workload begin
iter = Iterators.filter(x -> x != 10, 1:20);
wv(el) = 1.0
update_s!(rs, iter) = for x in iter update!(rs, x, wv(x)) end
@compile_workload begin
iter = Iterators.filter(x -> x != 10, 1:20);
wv(el) = 1.0
rs = ReservoirSample(Int, algARes)
for x in iter update!(rs, x, wv(x)) end
update_s!(rs, iter)
rs = ReservoirSample(Int, algAExpJ)
for x in iter update!(rs, x, wv(x)) end
update_s!(rs, iter)
rs = ReservoirSample(Int, 2, algARes)
for x in iter update!(rs, x, wv(x)) end
update_s!(rs, iter)
rs = ReservoirSample(Int, 2, algAExpJ)
for x in iter update!(rs, x, wv(x)) end
update_s!(rs, iter)
rs = ReservoirSample(Int, 2, algWRSWRSKIP)
for x in iter update!(rs, x, wv(x)) end
update_s!(rs, iter)
itsample(iter, algR)
itsample(iter, algL)
itsample(iter, 2, algR)
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
HypothesisTests = "09f84164-cd44-5f33-b23f-e6b0d136a0d5"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Expand Down
27 changes: 27 additions & 0 deletions test/benchmark_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@testset "benchmarks" begin
rng = Xoshiro(42)
iter = Iterators.filter(x -> x != 10, 1:10^4)
wv(el) = 1.0
for m in (algR, algL, algRSWRSKIP)
for size in (1, 10)
size == 1 && m === algRSWRSKIP && continue
s = size == 1 ? () : (10,)
b = @benchmark itsample($rng, $iter, $s..., $m) evals=1
mstr = "$m $(size == 1 ? :single : :multi)"
print(mstr * repeat(" ", 35-length(mstr)))
print(" --> Time: $(@sprintf("%.2f", median(b.times)*1e-3)) μs |")
println(" Memory: $(b.memory) bytes")
end
end
for m in (algARes, algAExpJ, algWRSWRSKIP)
for size in (1, 10)
size == 1 && m === algWRSWRSKIP && continue
s = size == 1 ? () : (10,)
b = @benchmark itsample($rng, $iter, $wv, $s..., $m) evals=1
mstr = "$m $(size == 1 ? :single : :multi)"
print(mstr * repeat(" ", 35-length(mstr)))
print(" --> Time: $(@sprintf("%.2f", median(b.times)*1e-3)) μs |")
println(" Memory: $(b.memory) bytes")
end
end
end
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

using BenchmarkTools
using Distributions
using HypothesisTests
using Printf
using Random
using StableRNGs
using Test
Expand All @@ -14,4 +16,5 @@ using StreamSampling
include("weighted_sampling_single_tests.jl")
include("weighted_sampling_multi_tests.jl")
include("merge_tests.jl")
include("benchmark_tests.jl")
end

0 comments on commit 8ec88c4

Please sign in to comment.