My lazy-sequence implementation was exactly following SICP: while
theoretically pure and good, might not be the best in practice, so I
believe your implementation can be much better.

Major performance boost in stateful implementation compared to
lazy-sequence with delay and force comes from removing essentially
cancelling each other delays and forces. Haskell has stream-fusion that
implements this idea differently and with the help from compiler, but
creates absolutely seamless interface to Haskell-lists — they’ve done very
clever work.

The disadvantage of stateful streams is their complete opaqueness, as at
every stage all they are is just a promise to do the computation.
​


Best regards,
Alexey

On 29 May 2015 at 12:14, Alexis King <lexi.lam...@gmail.com> wrote:

> > Hi, the full code is attached (I hope Google Groups will preserve it...).
>
> Thank you for this! There is absolutely a performance gap, and I'll
> definitely look over it and see if I can figure out exactly why (I think a
> well-built sequence-based model should have comparable speed). I did
> implement an equivalent test to the one in your blog post, which I've
> included at the end of this email. While the stateful implementation does
> indeed perform noticeably better, the results I got with my lazy
> implementation are not nearly as dire as you seem to have described.
>
> Specifically, the version operating on 100,000 elements and 1,000,000
> elements yielded the following times, respectively:
>
> ; cpu time: 774 real time: 774 gc time: 195
> ; cpu time: 7029 real time: 7045 gc time: 1814
>
> I did not encounter any out-of-memory problems in either test.
>
> The test I used is as follows:
>
> #lang racket
>
> (require alexis/collection)
>
> (define (sum seq)
>   (foldl + 0 seq))
>
> (define (test-sequence n foo)
>   (compose
>    sum
>    (curry take n)
>    (curry map foo)
>    (curry filter odd?)))
>
> (time
>  ((test-sequence
>    1000000
>    (lambda (x)
>      (* x
>         (sin (* pi (/ x 12)))
>         (+ 1 (exp (- (/ x 100)))))))
>   (in-naturals)))
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to