[racket] Tutorial: writing a language (brainf*ck) in Racket

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Tue Jun 21 16:48:10 EDT 2011

> Cool stuff, but you might want to compare to this example in PyPy:
>
>   http://morepypy.blogspot.com/2011/04/tutorial-part-2-adding-jit.html
>
> If you get numbers, please share them here!


Ah, I see!  I missed the link to the tutorial that explained out to
generate the JITed versions of example1.py through example5.py.  Ok,
so I'll use

    $ python ./pypy/pypy/translator/goal/translate.py example5.py

to produce a custom BF evaluator through PyPy, and use that for my
future tests.  I checked out a clone of pypy this afternoon.


Here are the numbers I see from the PyPy tutorial's evaluator for prime.b.

    $ echo 100 | time ./example5-c prime.b
    Primes up to: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67
71 73 79 83 89 97
    1.16user 0.00system 0:01.21elapsed 96%CPU (0avgtext+0avgdata 0maxresident)k
    0inputs+0outputs (0major+777minor)pagefaults 0swaps


My local bf language for Racket performs almost identically on this workload.

    fermi ~/work/bf/examples $ raco make prime.rkt && (echo 100 | time
racket prime.rkt)
    Primes up to: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67
71 73 79 83 89 97
    1.15user 0.06system 0:01.35elapsed 89%CPU (0avgtext+0avgdata 0maxresident)k
    120inputs+0outputs (0major+10365minor)pagefaults 0swaps


--------------------------------------------------------------------------------------------------------------

Under the mandelbrot benchmark, PyPy produces the following numbers:

   $ time ./example5-c mandel.b
   [after it produces the fractal...]
   real    1m9.891s
   user    1m9.128s
   sys     0m0.612s


A run with my bf language produces:

   $ raco make mandel.rkt && time racket mandel.rkt
    [after it produces the fractal...]
    real    0m48.837s
    user    0m47.435s
    sys     0m0.384s

As soon as I finish the rest of my tutorial, I'll update the reported
numbers accordingly.



Posted on the users mailing list.