[plt-scheme] Unreasonably slow

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Oct 29 10:32:39 EDT 2008


Let me confirm the following times and value on a 2G Intel mini-Mac,  
no debugging info:

   cpu time: 186221 real time: 187920 gc time: 81912
   104743

[The r5rs required seems unnecessary.]

;; ---

I also spent 3 minutes trying to port this to lazy Scheme but it's  
error-highlight is so, eh, lazy that it's no fun. -- Matthias




On Oct 29, 2008, at 9:28 AM, Alex Rozenshteyn wrote:

> I wrote this code for project euler problem 7:
>
> (require r5rs)
> (require srfi/41)
>
> (define stream-primes
>   (let ((numbers (stream-cons 2 (stream-from 3 2)))
>         (filter-stream
>           (stream-lambda
>             (divisor strm)
>             (let ((not-div
>                     (lambda (dividend)
>                       (not (zero? (modulo dividend divisor))))))
>               (stream-filter not-div strm)))))
>     (stream-let
>       loop
>       ((strm numbers)
>        (primes stream-null))
>       (define prime (stream-car strm))
>       (stream-append
>         (stream prime)
>         (loop (filter-stream prime (stream-cdr strm))
>               (stream-append primes (stream prime)))))))
>
> and I ran (stream-ref stream-primes 10000)
>
> It took unreasonably long to run.  Much longer than it took my  
> python code (which uses python's generators, to which srfi/41's  
> lazy comprehensions are as close as I can find in scheme).  I'm  
> curious as to whether this is an artifact of lazy comprehensions in  
> scheme being slow or just my code being wrong.
>
> Thank you to anyone who takes the time to read this.
>
> -- 
>          Alex R
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.