Skip to content

Commit d176153

Browse files
authored
Update benchmarks (#112)
* Update benchmarks * Update benchmark_comparison_non_stream_WWR.jl * Update benchmark_comparison_stream_WWR.jl
1 parent 2dad3b8 commit d176153

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

benchmark/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ StatsBase = "0.34"
1717
CairoMakie = "0.12"
1818
PyCall = "1.96"
1919
BenchmarkTools = "1.6"
20-
ChunkSplitter = "2"
20+
ChunkSplitter = "3"

benchmark/benchmark_comparison_non_stream_WWR.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function weighted_reservoir_sample_parallel_1_pass(rngs, a, ws, n)
6464
nt = Threads.nthreads()
6565
ss = Vector{Vector{eltype(a)}}(undef, nt)
6666
w_sums = Vector{Float64}(undef, nt)
67-
chunks_inds = chunks(a; n=nt)
67+
chunks_inds = index_chunks(a; n=nt)
6868
Threads.@threads for (i, inds) in enumerate(chunks_inds)
6969
s = weighted_reservoir_sample_seq(rngs[i], @view(a[inds]), @view(ws[inds]), n)
7070
ss[i], w_sums[i] = s
@@ -84,7 +84,7 @@ end
8484

8585
function weighted_reservoir_sample_parallel_2_pass(rngs, a, ws, n)
8686
nt = Threads.nthreads()
87-
chunks_inds = chunks(a; n=nt)
87+
chunks_inds = index_chunks(a; n=nt)
8888
w_sums = Vector{Float64}(undef, nt)
8989
Threads.@threads for (i, inds) in enumerate(chunks_inds)
9090
w_sums[i] = sum(@view(ws[inds]))
@@ -102,7 +102,7 @@ end
102102

103103
function sample_parallel_2_pass(rngs, a, ws, n)
104104
nt = Threads.nthreads()
105-
chunks_inds = chunks(a; n=nt)
105+
chunks_inds = index_chunks(a; n=nt)
106106
w_sums = Vector{Float64}(undef, nt)
107107
Threads.@threads for (i, inds) in enumerate(chunks_inds)
108108
w_sums[i] = sum(@view(ws[inds]))
@@ -190,26 +190,28 @@ def sample_times_numpy():
190190
"""
191191
times_numpy = py"sample_times_numpy()"
192192

193-
f = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98), size = (1100, 700));
193+
f = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98), size = (700, 600), dpi=1200);
194194

195195
ax1 = Axis(f[1, 1], yscale=log10, xscale=log10,
196196
yminorticksvisible = true, yminorgridvisible = true,
197-
yminorticks = IntervalsBetween(10))
197+
yminorticks = IntervalsBetween(10), xticklabelsize=15, yticklabelsize=15, titlesize=16,
198+
xlabelsize=17, ylabelsize=17,)
198199

199-
scatterlines!(ax1, [10^i/10^8 for i in 2:7], times_numpy[3:end], label = "numpy.choice sequential", marker = :circle, markersize = 12, linestyle = :dot)
200-
scatterlines!(ax1, [10^i/10^8 for i in 2:7], times_other[3:end], label = "StatsBase.sample sequential", marker = :rect, markersize = 12, linestyle = :dot)
201-
scatterlines!(ax1, [10^i/10^8 for i in 2:7], times_other_parallel[3:end], label = "StatsBase.sample parallel (2 passes)", marker = :diamond, markersize = 12, linestyle = :dot)
202-
scatterlines!(ax1, [10^i/10^8 for i in 2:7], times_single_thread[3:end], label = "WRSWR-SKIP sequential", marker = :hexagon, markersize = 12, linestyle = :dot)
203-
scatterlines!(ax1, [10^i/10^8 for i in 2:7], times_multi_thread[3:end], label = "WRSWR-SKIP parallel (1 pass)", marker = :cross, markersize = 12, linestyle = :dot)
204-
scatterlines!(ax1, [10^i/10^8 for i in 2:7], times_multi_thread_2[3:end], label = "WRSWR-SKIP parallel (2 passes)", marker = :xcross, markersize = 12, linestyle = :dot)
205-
Legend(f[2,1], ax1, labelsize=10, framevisible = false, orientation = :horizontal)
200+
scatterlines!(ax1, [10^i/10^8 for i in 2:7], times_numpy[3:end]./10^3, label = "numpy.choice sequential", marker = :circle, markersize = 12, linestyle = :dot)
201+
scatterlines!(ax1, [10^i/10^8 for i in 2:7], times_other[3:end]./10^3, label = "StatsBase.sample sequential", marker = :rect, markersize = 12, linestyle = :dot)
202+
scatterlines!(ax1, [10^i/10^8 for i in 2:7], times_other_parallel[3:end]./10^3, label = "StatsBase.sample parallel (2 passes)", marker = :diamond, markersize = 12, linestyle = :dot)
203+
scatterlines!(ax1, [10^i/10^8 for i in 2:7], times_single_thread[3:end]./10^3, label = "WRSWR-SKIP sequential", marker = :hexagon, markersize = 12, linestyle = :dot)
204+
scatterlines!(ax1, [10^i/10^8 for i in 2:7], times_multi_thread[3:end]./10^3, label = "WRSWR-SKIP parallel (1 pass)", marker = :cross, markersize = 12, linestyle = :dot)
205+
scatterlines!(ax1, [10^i/10^8 for i in 2:7], times_multi_thread_2[3:end]./10^3, label = "WRSWR-SKIP parallel (2 passes)", marker = :xcross, markersize = 12, linestyle = :dot)
206+
Legend(f[2,1], ax1, labelsize=12, framevisible = false, orientation = :horizontal, nbanks = 3)
206207

207208
ax1.xtickformat = x -> string.(round.(x.*100, digits=10)) .* "%"
208209
ax1.title = "Comparison between weighted sampling algorithms in a non-streaming context"
209210
ax1.xticks = [10^(i)/10^8 for i in 2:7]
211+
ax1.yticks = [10^float(i) for i in -1:1]
210212

211213
ax1.xlabel = "sample ratio"
212-
ax1.ylabel = "time (ms)"
214+
ax1.ylabel = "time (s)"
213215

214216
f
215217
save("comparison_WRSWR_SKIP_alg_no_stream.png", f)

benchmark/benchmark_comparison_stream_WWR.jl

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,41 +85,43 @@ end
8585

8686
using CairoMakie
8787

88-
f = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98), size = (1100, 700));
89-
90-
f.title = "Comparison between AExpJ-WR and WRSWR-SKIP Algorithms"
88+
f = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98), size = (700, 400), dpi=1200);
9189

9290
ax1 = Axis(f[1, 1], yscale=log10, xscale=log10,
93-
yminorticksvisible = true, yminorgridvisible = true,
94-
yminorticks = IntervalsBetween(10))
91+
yminorticksvisible = true, yminorgridvisible = true, xlabelsize=16, ylabelsize=16,
92+
yminorticks = IntervalsBetween(10), xticklabelsize=11, titlesize=16)
9593
ax2 = Axis(f[1, 2], yscale=log10, xscale=log10,
94+
yminorticksvisible = true, yminorgridvisible = true, xlabelsize=16,
95+
yminorticks = IntervalsBetween(10), xticklabelsize=11, titlesize=16)
96+
ax3 = Axis(f[1, 3], yscale=log10, xscale=log10, xlabelsize=16,
9697
yminorticksvisible = true, yminorgridvisible = true,
97-
yminorticks = IntervalsBetween(10))
98-
ax3 = Axis(f[1, 3], yscale=log10, xscale=log10,
99-
yminorticksvisible = true, yminorgridvisible = true,
100-
yminorticks = IntervalsBetween(10))
98+
yminorticks = IntervalsBetween(10), xticklabelsize=11, titlesize=16)
99+
100+
linkyaxes!(ax1, ax2, ax3)
101101

102-
#ax4 = Axis(f[2, 1])
102+
hideydecorations!(ax2, grid=false, minorgrid=false)
103+
hideydecorations!(ax3, grid=false, minorgrid=false)
103104

104105
for x in benchs
105-
label = x[1] == :wv_const ? (x[2] == AlgAExpJWR() ? "ExpJ-WR" : "WRSWR-SKIP") : ""
106+
label = x[1] == :wv_const ? (x[2] == AlgAExpJWR() ? "A-ExpJ-WR" : "WRSWR-SKIP") : ""
106107
ax = x[1] == :wv_decr ? ax1 : (x[1] == :wv_const ? ax2 : ax3)
107108
marker = x[2] == AlgAExpJWR() ? :circle : (:xcross)
108-
scatterlines!(ax, [10^i/10^8 for i in 3:7], x[3] ./ 10^6, marker = marker,
109+
scatterlines!(ax, [10^i/10^8 for i in 4:7], x[3][2:end] ./ 10^9, marker = marker,
109110
label = label, markersize = 12, linestyle = :dot)
110111
end
111112

112-
Legend(ax4, labelsize=10, framevisible = false, orientation = :horizontal)
113+
Legend(f[2,:], ax2, labelsize=12, markersize=2, framevisible=false, orientation = :horizontal)
114+
rowsize!(f.layout, 1, Relative(4/5))
113115

114116
for ax in [ax1, ax2, ax3]
115117
ax.xtickformat = x -> string.(round.(x.*100, digits=10)) .* "%"
116118
#ax.ytickformat = y -> y .* "^"
117119
ax.title = ax == ax1 ? "decreasing weights" : (ax == ax2 ? "constant weights" : "increasing weights")
118-
ax.xticks = [10^(i)/10^8 for i in 3:7]
119-
ax.yticks = [10^i for i in 2:4]
120+
ax.xticks = [10^(i)/10^8 for i in 4:7]
121+
ax.yticks = [10^float(i) for i in -1:1]
120122
ax.xlabel = "sample ratio"
121-
ax == ax1 && (ax.ylabel = "time (ms)")
123+
ax == ax1 && (ax.ylabel = "time (s)")
122124
end
123125

124126
save("comparison_WRSWR_SKIP_alg_stream.png", f)
125-
f
127+
f

0 commit comments

Comments
 (0)