<div dir="ltr"><div>The documentation says that one should expect typed/racket to be faster than racket. I tested the math/matrix library and it seems to be almost as slow in typed/racket as in racket. Here is the program in typed racket:<br>
<br>#lang typed/racket ; file: matrix.rkt<br>(require math/matrix)<br><br>(: mx Index)<br>(define mx 600)<br><br>(: r (Index Index -> Flonum))<br>(define (r i j) (random))<br><br>(: A : (Matrix Flonum))<br>(define A (build-matrix mx mx r))<br>
<br>(: sum : Integer Integer -> Flonum)<br>(define (sum i n)<br> (let loop ((j 0) (acc 0.0)) <br> (if (>= j mx) acc<br> (loop (+ j 1) (+ acc (matrix-ref A i j))) )))<br><br>(: b : (Matrix Flonum))<br>(define b (build-matrix mx 1 sum))<br>
<br>(let [(m (matrix-solve A b))]<br> (displayln (matrix-ref m 0 0)))<br><br></div><div>You can run it thus:<br><br></div><div>time racket matrix.rkt<br><br></div><div>What should I do to speedup the above code?<br></div>
</div>