You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, cool packages!, I really did not want to go through the hassle of defining all iterator syntax... and this seems the prefect solution for that hehe
I'm working on a 0 alloc file reader and to make this work I use views of the lines, however when benchmarking I saw my code results in allocations when used with Continuables. I made this minimal example on array views (instead of char views):
using Continuables
using BenchmarkTools
view_test(n::Integer, arr::Vector{Int}) = @cont begin
for i in 1:length(arr)
v = view(arr, i:n)
cont(v)
end
end
function t1(arr::Vector{Int64})
tot = 0
for i in 1:length(arr)
v = view(arr, i:length(arr))
tot += length(v)
end
return tot
end
function t2(arr::Vector{Int64})
tot = 0
foreach(view_test(length(arr), arr)) do x
tot += length(x)
end
return tot
end
test_arr = zeros(Int64, 1_000)
@btime t1($test_arr)
@btime t2($test_arr)
P.s. I saw the doc about Ref(). While I might be able to use Ref(tot) here, in my file reader I basically "yield" lines based on numerous condition rather than simply adding up something (see my Julia discourse implementation of the reader).
Is there any way to prevent all these allocs? That would be awesome :)
The text was updated successfully, but these errors were encountered:
Hey!
First of all, cool packages!, I really did not want to go through the hassle of defining all iterator syntax... and this seems the prefect solution for that hehe
I'm working on a 0 alloc file reader and to make this work I use
views
of the lines, however when benchmarking I saw my code results in allocations when used withContinuables
. I made this minimal example on arrayviews
(instead of char views):Which gives:
P.s. I saw the doc about
Ref()
. While I might be able to useRef(tot)
here, in my file reader I basically "yield" lines based on numerous condition rather than simply adding up something (see my Julia discourse implementation of the reader).Is there any way to prevent all these allocs? That would be awesome :)
The text was updated successfully, but these errors were encountered: