[racket] Is eval very slow?

From: Joe Gilray (jgilray at gmail.com)
Date: Thu Jul 19 02:58:40 EDT 2012

Thanks John and Rudiger,

Yes, I can and will rewrite the code... I was just shocked at how slow eval
was.

-Joe


On Wed, Jul 18, 2012 at 10:52 PM, Rüdiger Asche <rac at ruediger-asche.de>wrote:

> **
> yes it is:
>
> (define thunk1 (lambda () (/ 100 10)))
> (define thunk2 (lambda () (eval '(/ 100 10))))
> (define iterate (lambda (ct thunk)
>                       (if (zero? ct)
>                          #t (begin (thunk) (iterate (- ct 1) thunk)))))
>
> (time (iterate 1000000 thunk1))
>  => cpu time: 15 real time: 16 gc time: 0
>
> (time (iterate 1000000 thunk2))
> => cpu time: 21110 real time: 21125 gc time: 436
>
>
>
>
> ----- Original Message -----
> *From:* Joe Gilray <jgilray at gmail.com>
> *To:* Racket mailing list <users at racket-lang.org>
> *Sent:* Thursday, July 19, 2012 7:15 AM
> *Subject:* [racket] Is eval very slow?
>
> Hi,
>
> I've written some code that uses eval:
>
>    (define ops (list * / + -))
>   (define digits '(1 2 3 4 5))
>   (for ([dl (combinations 4 digits)])
>     (define lst '())
>     (for ([d (permute-all dl)])
>       (for* ([o1 ops] [o2 ops] [o3 ops])
>         (unless (and (eq? o1 /) (zero? (eval (list o2 (second d) (list o3
> (third d) (fourth d))))))  ; avoid divide by zero
>           (define val (eval (list o1 (first d) (list o2 (second d) (list
> o3 (third d) (fourth d))))))
>           (when (>= val 1) (set! lst (cons val lst)))) ...
>
> It runs very, very slowly.  Am I doing something wrong?  Is there a way to
> speed up eval?
>
> Thanks,
> -Joe
>
> ------------------------------
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120718/3aaff9bd/attachment-0001.html>

Posted on the users mailing list.