Last active
September 14, 2020 18:15
-
-
Save aviatesk/c1026108f94a956db8dd3d9758739243 to your computer and use it in GitHub Desktop.
flatten flatten
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
using BenchmarkTools, Cthulhu | |
f(a, b) = collect(Iterators.flatten((a, b))) | |
a = rand(10^6) | |
b = rand(10^6) | |
@btime f($a, $b) # 14.402 ms (21 allocations: 17.00 MiB) | |
# @descend f(a, b) | |
(@code_typed iterate(Iterators.flatten((a,b)))) |> last # ::Union{Nothing, Tuple{Float64, Tuple{Int64, Vector{Float64}, Int64}}} -> unwidened | |
a′ = rand(10^6) | |
b′ = @view a′[end-1:-1:2] | |
@btime f($a′, $b′) # 242.919 ms (8000021 allocations: 405.73 MiB) | |
# @descend f(a′, b′) | |
(@code_typed iterate(Iterators.flatten((a′,b′)))) |> last # ::Union{Nothing, Tuple{Float64, Tuple{Union{Int64, SubArray{Float64, 1, Vector{Float64}, Tuple{StepRange{Int64, Int64}}, true}, Vector{Float64}}, Union{Int64, SubArray{Float64, 1, Vector{Float64}, Tuple{StepRange{Int64, Int64}}, true}, Vector{Float64}}, Union{Int64, Tuple{Base.OneTo{Int64}, Int64}}}}} -> too complex, widened |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment