[plt-scheme] Benchmarks using R5RS only?
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? Under
Unix, I suppose I could use the time utility, but it would be nice to
be able to time specific evaluations, too.
Here's the program:
;;This function just generates a (pseudo-random) list
;;for test purposes.
(define random-list
(lambda (size range)
(if (> size 0)
(cons (random range)
(random-list (- size 1) range))
'())))
;;The standard quicksort algorithm
(define quick
(lambda (l)
(if (null? l) '()
(let ((p (car l))
(l (cdr l)))
(append
(quick (filter (lambda (x) (< x p)) l))
(list p)
(quick (filter (lambda (x) (not (< x p))) l)))))))
;;try-it
(define try-it
(lambda (n)
(begin
(define output '())
(time (set! output (quick (random-list n 1000)))))))
;;test-run
;;Note that this benchmark times the process of both building the
list to sort
;;(using a pseudo-random number generator) and sorting it
(define test-run
(lambda (n)
(let loop
((i 1))
(begin
(display "i = ")
(display i)
(display " (")
(display (* i 1000))
(display " items)")
(newline)
(try-it (* i 1000)))
(if (< i n)
(loop (+ i 1))))))
;;Try it!
(begin
(display "How many increments? ")
(define count (read))
(newline)
(test-run count))
===
Gregory Woodhouse
gregory.woodhouse at sbcglobal.net
"The most profound technologies are those that disappear."
--Mark Weiser