From fbc2e437115c84730ccd98acfe4f2eeb0f3d39fd Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Mon, 6 Jan 2020 13:53:10 -0800 Subject: [PATCH] Add benchmarks for foldl on iterators --- src/misc/MiscellaneousBenchmarks.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/misc/MiscellaneousBenchmarks.jl b/src/misc/MiscellaneousBenchmarks.jl index 35d9cb84..722d5511 100644 --- a/src/misc/MiscellaneousBenchmarks.jl +++ b/src/misc/MiscellaneousBenchmarks.jl @@ -280,6 +280,20 @@ for T in (Float32, Float64, Complex{Float32}, Complex{Float64}) g[string(T)] = @benchmarkable perf_copy_23042($(Foo_23042(a)), $(Foo_23042(b))) end +############################################### +# foldl + +g = addgroup!(SUITE, "foldl", ["filter", "flatten"]) + +let xs = [abs(x) < 1 ? x : missing for x in randn(1000)] + g["foldl(+, filter(...))"] = @benchmarkable foldl(+, (x for x in $xs if x !== missing)) + g["foldl(+, filter(...); init = 0.0)"] = + @benchmarkable foldl(+, (x for x in $xs if x !== missing); init = 0.0) +end + +g["foldl(+, flatten(filter(...)))"] = + @benchmarkable foldl(+, (y for x in 1:1000 for y in 1:x if y % 2 == 0)) + ############################################### # iterators