Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
418 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module BenchCartesian | ||
|
||
using BenchmarkTools | ||
using Transducers | ||
|
||
function copyto_manual!(ys::AbstractMatrix, xs::AbstractMatrix) | ||
@assert axes(ys) == axes(xs) | ||
for j in 1:size(xs, 2), i in 1:size(xs, 1) | ||
@inbounds ys[i, j] = xs[i, j] | ||
end | ||
return ys | ||
end | ||
|
||
function copyto_iter!(ys, xs) | ||
@assert axes(ys) == axes(xs) | ||
for I in CartesianIndices(xs) | ||
@inbounds ys[I] = xs[I] | ||
end | ||
return ys | ||
end | ||
|
||
function copyto_xf!(ys, xs) | ||
foreach(Map(identity), CartesianIndices(xs)) do I | ||
@inbounds ys[I] = xs[I] | ||
nothing | ||
end | ||
return ys | ||
end | ||
|
||
const SUITE = BenchmarkGroup() | ||
|
||
let xs = randn(3, 10^3) | ||
ys = zero(xs) | ||
s1 = SUITE["copyto!"] = BenchmarkGroup() | ||
s1["man"] = @benchmarkable(copyto_manual!($ys, $xs)) | ||
s1["iter"] = @benchmarkable(copyto_iter!($ys, $xs)) | ||
s1["xf"] = @benchmarkable(copyto_xf!($ys, $xs)) | ||
end | ||
|
||
end # module | ||
BenchCartesian.SUITE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module BenchFilterSum | ||
|
||
import Random | ||
using BenchmarkTools | ||
using Transducers | ||
|
||
const SUITE = BenchmarkGroup() | ||
|
||
function naive_sum(xs, acc = false) | ||
for x in xs | ||
acc += x | ||
end | ||
return acc | ||
end | ||
|
||
Random.seed!(12345) | ||
for n in [1000, 10000] | ||
s0 = SUITE[string(n)] = BenchmarkGroup() | ||
|
||
for (xslabel, xs, init) in [ | ||
("UnitRange", (x for x in 1:n if isodd(x)), 0), | ||
("RandomFloats", (x for x in randn(n) if x > 0), 0.0), | ||
] | ||
s1 = s0[xslabel] = BenchmarkGroup() | ||
|
||
s2 = s1["noinit"] = BenchmarkGroup() | ||
s2["naive"] = @benchmarkable naive_sum($xs) | ||
s2["base"] = @benchmarkable sum($xs) | ||
s2["xf"] = @benchmarkable sum($(eduction(xs))) | ||
|
||
s2 = s1["withinit"] = BenchmarkGroup() | ||
s2["naive"] = @benchmarkable naive_sum($xs, $init) | ||
s2["base"] = @benchmarkable foldl(+, $xs; init = $init) | ||
s2["xf"] = @benchmarkable foldl(+, $(eduction(xs)); init = $init) | ||
end | ||
end | ||
|
||
end # module | ||
BenchFilterSum.SUITE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module BenchSumTranspose | ||
|
||
import Random | ||
using BenchmarkTools | ||
using Transducers | ||
|
||
const SUITE = BenchmarkGroup() | ||
|
||
function iter_sum(xs, acc = false) | ||
for x in xs | ||
acc += x | ||
end | ||
return acc | ||
end | ||
|
||
function man_sum(xs::AbstractMatrix, acc = false) | ||
for i in axes(xs, 2), j in axes(xs, 1) | ||
acc += @inbounds xs[j, i] | ||
end | ||
return acc | ||
end | ||
|
||
Random.seed!(12345) | ||
# for n in [30, 100] | ||
let n = 30 | ||
s1 = SUITE[string(n)] = BenchmarkGroup() | ||
|
||
xs = randn(n, n)' | ||
|
||
s2 = s1["noinit"] = BenchmarkGroup() | ||
s2["iter"] = @benchmarkable iter_sum($xs) | ||
s2["man"] = @benchmarkable man_sum($xs) | ||
s2["xf"] = @benchmarkable foldxl(+, $xs) | ||
|
||
s2 = s1["withinit"] = BenchmarkGroup() | ||
s2["iter"] = @benchmarkable iter_sum($xs, 0.0) | ||
s2["man"] = @benchmarkable man_sum($xs, 0.0) | ||
s2["xf"] = @benchmarkable foldxl(+, $xs; init = 0.0) | ||
end | ||
|
||
end # module | ||
BenchSumTranspose.SUITE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module BenchTeeRFFilter | ||
|
||
using BenchmarkTools | ||
using Transducers | ||
|
||
const SUITE = BenchmarkGroup() | ||
|
||
let xs = 1:1000 | ||
rf = TeeRF(Filter(isodd)'(+), Filter(iseven)'(+)) | ||
|
||
SUITE["noinit"] = @benchmarkable foldxl($rf, $xs) | ||
SUITE["withinit"] = @benchmarkable foldxl($rf, $xs; init = (0, 0)) | ||
end | ||
|
||
end # module | ||
BenchTeeRFFilter.SUITE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.