作为一名 Linux管理员,我曾经用Bash,TCL和Perl编写脚本.出于好奇,我试着用mzscheme写一些东西,但我发现的是性能差得多.我将脚本剪切为简单地读取500MB日志文件: #lang scheme(require rnrs/progra
#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))))))
这个简单的过程大约需要40秒.适用于Guile的相同脚本在10秒内执行. TCL版本运行5秒钟.鸡肉计划仅需3.8秒,比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))))))
我究竟做错了什么?是否有关于编写更快的MZScheme程序的建议?
更多测试:
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现在,在Racket的开发版本中已经大大改进了这一点.请参阅commit here和来自Racket maintainer Matthew Flatt here的消息.现在它应该比Chicken慢大约50%.剩余的减速主要是由于Racket提供的附加功能,例如事件,行计数,unicode编码等.