Skip to content

Commit

Permalink
Add multi-thread/bench_sum.jl (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf authored and mergify[bot] committed Jan 22, 2020
1 parent 9b1ee9d commit 19c510d
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions benchmark/multi-thread/bench_sum.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module BenchSum

using BenchmarkTools
using Transducers

suite = BenchmarkGroup()

function slow_computation(n)
x = 0.4
for _ in 1:n
x = 3 / π * sin(x * π)
end
return x
end

xf = Map(slow_computation)

n = 2^14
maxworkload = 100
inputtable = [
("uniform", fill(maxworkload ÷ 2, n)),
("random", rand(1:maxworkload, n)),
#=
("increasing", ceil.(Int, range(1, maxworkload, length = n))),
("decreasing", ceil.(Int, range(maxworkload, 1, length = n))),
(
"mountain",
vcat(
ceil.(Int, range(1, maxworkload, length = n ÷ 2)),
ceil.(Int, range(maxworkload, 1, length = n ÷ 2)),
),
),
=#
(
"valley",
vcat(
ceil.(Int, range(maxworkload, 1, length = n ÷ 2)),
ceil.(Int, range(1, maxworkload, length = n ÷ 2)),
),
),
]

for (label, xs) in inputtable
s1 = suite[label] = BenchmarkGroup()
s1["foldl"] = @benchmarkable foldl(+, $xf, $xs; simd = true)
s2 = s1["reduce"] = BenchmarkGroup()
for basesize in 2 .^ (7:9)
s2["basesize=$basesize"] = @benchmarkable reduce(
+,
$xf,
$xs;
basesize = $basesize,
simd = true,
)
end
end

end # module
BenchSum.suite

0 comments on commit 19c510d

Please sign in to comment.