Re: Going live

"Neil W. Van Dyke" <[email protected]>
Newsgroups gmane.lisp.scheme.plt.schematics
Message-ID <[email protected]>
Brent A. Fulgham <[email protected]> writes at 18:06 05-Jun-2004 -0700:
> Just to show I've not been totally idle, you might enjoy taking a peek 
> at this:

Looks snazzy, although some of the MzScheme numbers are dismal.

In our copious spare time, we could improve the programs used to
benchmark MzScheme.  For example, on my test input, the current "wc"
program used for the MzScheme interpreter in the shootout takes about
8.0 seconds (once the file is in RAM cache by the OS), whereas the two
more idiomatic programs below take 3.5 and 3.9 seconds, respectively.

(Note that this is just idiomatic Scheme, like a Scheme programmer would
write everyday to accomplish the behavior specified by the benchmark,
not excessive tuning or optimization, so I think it's fair game.  Now,
if I whipped out MzScheme's "read-string-avail" and
"regexp-match-positions", and tuned the block reads for the host OS,
*that* would be less OK, if it worked.)

(define (main p)
  (letrec ((i (lambda (l w c)
                (let ((x (read-char p)))
                  (if (eof-object? x)
                      (list l w c)
                      (case x
                        ((#\newline)     (o (add1 l) w (add1 c)))
                        ((#\space #\tab) (o       l  w (add1 c)))
                        (else            (i       l  w (add1 c))))))))
           (o (lambda (l w c)
                (let ((x (read-char p)))
                  (if (eof-object? x)
                      (list l w c)
                      (case x
                        ((#\newline)     (o (add1 l)       w  (add1 c)))
                        ((#\space #\tab) (o       l        w  (add1 c)))
                        (else            (i       l  (add1 w) (add1 c)))))))))
    (apply printf "~s ~s ~s\n" (o 0 0 0))))


(define (main p)
  (apply printf "~s ~s ~s\n"
         (let wc ((i #f) (l 0) (w 0) (c 0))
           (let ((x (read-char p)))
             (if (eof-object? x)
                 (list l w c)
                 (case x
                   ((#\newline)     (wc #f (add1 l) w (add1 c)))
                   ((#\space #\tab) (wc #f l        w (add1 c)))
                   (else (wc #t l (if i w (add1 w)) (add1 c)))))))))


-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X.
From Windows to Linux, servers to mobile, InstallShield X is the one
installation-authoring solution that does it all. Learn more and
evaluate today! http://www.installshield.com/Dev2Dev/0504
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.