I implemented a type for defining arbitrary lazy sequences that performs well, but the implementation is so trivial that I'm not sure if it's worth making a package

Hi

I have recently improved ResumableFunctions and the benchmark is a lot better with your code. However the benchmark is not completely fair because you are using an iterator to make an iterator in the @resumable function implementation. You can code a @resumable function in the same way as the other implementations:

@resumable function resumable_counter2(start::Int, stop::Int)
    while start <= stop
        @yield start
        start += 1
    end
end

These are the benchmarks I got:

channel
  2.786 ms (23 allocations: 1.88 KiB)
lazy
  210.987 μs (1588 allocations: 32.84 KiB)
resumable
  128.684 ns (1 allocation: 64 bytes)
resumable2
  77.302 ns (1 allocation: 32 bytes)
sequence
  48.012 ns (0 allocations: 0 bytes)
custom
  51.960 ns (0 allocations: 0 bytes)

This is a fair result knowing that a @resumable function does a lot more than simply being a generator.

Kind regards

Ben

2 Likes

Thanks for the update on this, Ben! I’ll link to this post in the original benchmark post.

Edit: oops. I can no longer edit the post… hm…