minaev
minaev

Reputation: 299

I/O performance in mzscheme

Being a Linux administrator, I used to write my scripts in Bash, TCL and, less often, in Perl. Just out of curiosity, I tried to write something in mzscheme, but what I found out was that the performance was so much worse. I cut the script to simply reading a 500MB log file:

#lang scheme
(require rnrs/programs-6)
(call-with-input-file (vector-ref (current-command-line-arguments) 0)
    (lambda (in)
            (let loop ((line (read-line in)))
                    (unless (eof-object? line)
                            (loop (read-line in))))))

This simple process takes about 40 seconds. The same script, adapted for Guile, executes in 10 seconds. TCL version runs for 5 seconds. Chicken Scheme takes only 3.8 seconds, ten time less than MZScheme:

#!/usr/bin/csi -script
(call-with-input-file (list-ref (command-line-arguments) 0)
    (lambda (in)
            (let loop ((line (read-line in)))
                    (if (not (eof-object? line))
                            (loop (read-line in))))))

What am I doing wrong? Are there any recommendations on writing faster MZScheme programs?

Some more tests:

minaev@minaev:~/1$ time ./t.tcl blog.log

real    0m8.907s
user    0m8.417s
sys     0m0.468s
Mon Oct 31 13:15:19 MSK 2011
minaev@minaev:~/1$ time ./t.scm blog.log # Chicken 4.2.0

real    0m7.678s
user    0m6.896s
sys     0m0.580s
Mon Oct 31 13:15:29 MSK 2011
minaev@minaev:~/1$ time /usr/bin/mzscheme t.ss blog.log # mzscheme 4.2.1

real    0m44.047s
user    0m41.803s
sys     0m0.948s
Mon Oct 31 13:17:03 MSK 2011
minaev@minaev:~/1$ time racket t.ss blog.log  # racket 5.1.3

real    0m25.287s
user    0m23.189s
sys     0m0.828s
Mon Oct 31 13:17:39 MSK 2011
minaev@minaev:~/1$ raco make t.ss
Mon Oct 31 13:17:47 MSK 2011
minaev@minaev:~/1$ time racket t.ss blog.log  # racket 5.1.3 byte-compiled

real    0m23.237s
user    0m22.469s
sys     0m0.688s

Upvotes: 4

Views: 449

Answers (2)

Sam Tobin-Hochstadt
Sam Tobin-Hochstadt

Reputation: 5053

This has now been substantially improved in the development version of Racket. See the commit here and the message from Racket maintainer Matthew Flatt here. It should now be only about 50% slower than Chicken. The remaining slowdown is primarily due to the additional features Racket provides, such as events, line-counting, unicode encoding, and others.

Upvotes: 3

Ryan Culpepper
Ryan Culpepper

Reputation: 10663

I tried repeating your results, and I got about 3.4s for Chicken 4.5.0 and about 10s for various versions of mzscheme/racket. (I tried mzscheme from PLT Scheme 4.2 and racket from both Racket 5.1.1 and the development tree, all compiled in 64-bit mode.)

What version of mzscheme are you using? What platform?

Are your timings repeatable? (I wonder about block cache effects.)

Upvotes: 1

Related Questions