[racket] Is eval very slow?

From: Rüdiger Asche (rac at ruediger-asche.de)
Date: Thu Jul 19 01:52:24 EDT 2012

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 
  To: Racket mailing list 
  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/20120719/a9617bee/attachment.html>

Posted on the users mailing list.