<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">I think that number crunching is so important that it should receive ad hoc optimization, if a more general approach fails. To bring the discussion to a concrete example, I attached a small benchmark to this article. PLT, Bigloo and Gambit take about the same time to run the program below. However, Bigloo and Gambit become ten times faster with a very simple optimization.<br><br> (define-syntax $<br>
(syntax-rules ()<br>
( ($ m c i j) (vector-ref m (+fx (*fx c i) j)))<br>
)<br>
)<br>
<br>
(define-syntax $!<br>
(syntax-rules ()<br>
( ($! m c i j v) (vector-set! m (+fx (*fx c i) j) v))<br>
)<br>
)<br>
<br>BTW, use the option -Obench to compile Bigloo. When one uses the *fx, +fx, *fl, +fl and /fl in few other places, Bigloo speed is multiplied by 20 (the time is divided by 20). It would be great if PLT had similar directives to control optimization. <br><br>If I missed something, and there is a way to make PLT approach the speed of Bigloo and Gambit in the example below, please let me know. However, I read an article in this list, where you people suggest exactly this, to add unsafe arithmetic operators to improve performance. <br><br><br><br>(module matplt scheme<br> (require (lib "4.ss" "srfi"))<br> <br> (define iii 0)<br><br> (define-syntax $mk<br> (syntax-rules ()<br> ( ($mk c v) (make-vector c v)) ))<br><br> (define-syntax $<br> (syntax-rules ()<br> ( ($ m c i j) (vector-ref m (+ (* c i)
j)))<br> )<br> )<br> <br> (define-syntax $!<br> (syntax-rules ()<br> ( ($! m c i j v) (vector-set! m (+ (* c i) j) v))<br> )<br> )<br> <br> <br><br><br>(define (prt m r c)<br> (do ( (i 0 (+ i 1)) ) ( (>= i r) )<br> (newline)<br> (do ((j 0 (+ j 1)) ) ( (>= j c) )<br> (printf " %4.3f " ($ m c i j) ) )))<br><br>(define (make-system r)<br> (let* ( (c (+ r 1))<br> (m ($mk (* r c) 0.0 )) <br> (xx 0.0)<br> (s 0.0) )<br><br> (do ( (i 0 (+ i 1)) ) (
(>= i r) m)<br> (set! s 0.0)<br> (do ((j 0 (+ j 1) ) ) ( (>= j r) ($! m c i j s) )<br> (set! xx (exact->inexact (random 3873)))<br> (set! s (+ s xx))<br> ($! m c i j xx )) ) ))<br><br>(define (swapit m c k l)<br> (let ((t 0.0))<br> (set! iii (+ iii 1))<br> (do ( (j 0 (+ j 1)) ) ( (>= j c) )<br> (set! t ($ m c k j ) )<br> ($! m c k j ($ m c l j) )<br> ($! m c l j t) ) ) )<br><br>(define (find-max m c k i)<br> (do ( (l (+ k 1) (+ l 1)) ) <br> ( (>= l
(- c 1)) (when (not (= i k)) (swapit m c k i )))<br> (when (> (abs ($ m c l k)) (abs ($ m c i k)) )<br> (set! i l) ) ))<br><br>(define (solvit m r)<br> (let ( (c (+ r 1)) <br> (rat 0.0)<br> (mkk 0.0))<br> <br> (do ( (k 0 (+ k 1)) ) ( (>= k (- r 1)))<br> (find-max m c k k)<br> (set! mkk ($ m c k k) ) <br> <br> (do ( ( i (+ k 1)(+ i 1)) ) ( (>= i r))<br> (set! rat
(/ ($ m c i k) mkk ))<br> (do ( (j k (+ j 1))) ( (>= j c) )<br> ($! m c i j (- ($ m c i j) <br> (* rat ($ m c k j ) ) ) )<br> ) <br> ) <br> ) <br> <br> (do ( (i (- r 1) (- i 1) ) ) ((< i 0) m)<br> (do ( (j (+ i 1) (+ j 1))
<br> (tx 0.0 (- tx (* ($ m c i j) <br> ($ m c j r )) )) )<br> ( (>= j r)<br> ($! m c i r <br> (/ (+ ($ m c i r ) tx)<br> ($ m c i i)) ) ) ))<br> )<br>) <br> <br>(define (elms argv)<br> (cond (
(< (length argv) 2) 2000)<br> ( (string->number (cadr argv)) (string->number (cadr argv)) )<br> (else 2000)))<br><br>(define (main argv)<br> (let* ( (r (elms argv)) (c (+ r 1)) (m (solvit (make-system r) r) ) ) <br> (do ( (i 0 (+ i 1))) ( (>= i (min r 10)) )<br> (display (list($ m c i r)) ) ) <br> (newline) <br> (newline) (display iii)) )<br> <br> (time (main '(xx "500")))<br> <br>)<br><br><br></td></tr></table><br>
<hr size=1>Instant message from any web browser! Try the new <a href="http://ca.messenger.yahoo.com/webmessengerpromo.php"><b> Yahoo! Canada Messenger for the Web BETA</b></a>