[racket] "compiling" evaluation of an arbitrary s-expression

From: Stephen Bloch (sbloch at adelphi.edu)
Date: Tue Jun 7 11:11:19 EDT 2011

On Jun 7, 2011, at 10:27 AM, Robby Findler wrote:

> Put the call to eval outside and add the wrapper `(lambda (x y)
> ,code-with-x-and-y-free). Then just call that function each time,
> instead of calling eval each time.

Duh!  That works nicely, and doesn't require anything I don't already know :-)

Here's a 100x100 benchmark:

body copied-and-pasted into function definition:
cpu time: 157 real time: 157 gc time: 0

calling eval for each pixel:
cpu time: 48313 real time: 48476 gc time: 8972

calling eval once around a lambda, as Robby suggests:
cpu time: 189 real time: 190 gc time: 53

Thanks!  I was sure there was something like that....


Stephen Bloch
sbloch at adelphi.edu




Posted on the users mailing list.