[plt-scheme] Benchmarks using R5RS only?

From: Gregory Woodhouse (gregory.woodhouse at sbcglobal.net)
Date: Thu Jan 12 09:40:23 EST 2006

On Jan 12, 2006, at 5:46 AM, Jens Axel Søgaard wrote:

> Gregory Woodhouse wrote:
>> I was curious to see how fast Quicksort would be in PLT Scheme  
>> and  how much difference compilation would make, so I wrote a  
>> little  program (see below). It won't run under R5RS, though,  
>> because it uses  random (which I can implement) and time (which I  
>> do not know how to  implement). How can I modify this code to run  
>> under R5RS only?
>
> If you mean the R5RS-language in PLT Scheme you can use this trick:
>
>     (#%require (only mzscheme random))

No, I really mean R5RS only, or at least portable across Scheme  
implementations.
>
> Otherwise just generate a large random list and put a
>
> (define a-random-list (list 1 4 1 4 2 ...))

I can implement the usual pseudo-random number generator from  
scratch. This isn't a big deal.
>
> at the top of the file.
>
>
>> ;;try-it
>> (define try-it
>>   (lambda (n)
>>     (begin
>>       (define output '())
>>       (time (set! output (quick (random-list n 1000)))))))
>
> If you use the time function, you should garbage collect first,
> so the function you want to time doesn't get penalized by a previous
> evaluation.
>
>  (define try-it
>    (lambda (n)
>      (begin
>        (define output '())
>        (collect-garbage)
>        (time (set! output (quick (random-list n 1000)))))))

Actually, I didn't know how to force garbage collection! In fact, it  
was kind of interesting to see how often garbage collection would  
occur, but I'll make this change.
>
>
> BTW - were you comparing DrScheme times with MzScheme? If so,
> remember that you under language details can get DrScheme to
> run faster if you remove the debug information.

In fact, I did try generating an executable from within DrScheme (I  
haven't tried to use mzc yet) and found that the speedup was  
dramatic. In DrScheme I get

How many increments? 4

i = 1 (1000 items)
cpu time: 83 real time: 92 gc time: 0
i = 2 (2000 items)
cpu time: 201 real time: 224 gc time: 0
i = 3 (3000 items)
cpu time: 308 real time: 326 gc time: 0
i = 4 (4000 items)
cpu time: 459 real time: 484 gc time: 0
 >

With the compiled version (same system) I get

How many increments? 4

i = 1 (1000 items)
cpu time: 59 real time: 67 gc time: 0
i = 2 (2000 items)
cpu time: 123 real time: 131 gc time: 0
i = 3 (3000 items)
cpu time: 182 real time: 193 gc time: 0
i = 4 (4000 items)
cpu time: 231 real time: 244 gc time: 0

(I was actually doing 20 or 30 increments, but don't want to waste  
bandwidth.)

I really had two questions for asking. One was that a colleague of  
mine was able to install Scheme48 under Debian but not PLT Scheme.  
I'll have to talk to her later, but we're on opposite coasts, so I  
can't really see what she was doing. Another is that I have this  
crazy idea of trying to write a tutorial (perhaps as a way of forcing  
myself to learn this stuff!) and it would be nice to have platform  
independent examples.


>
> -- 
> Jens Axel Søgaard
>
>
>

===
Gregory Woodhouse
gregory.woodhouse at sbcglobal.net

"The most incomprehensible thing about
the world is that it is at all comprehensible."
  --Albert Einstein (1879-1955)





Posted on the users mailing list.