Where are you seeing the slowness in that code? For me the majority of the time is spent in matrix-solve, and since that is another module it doesn't matter what you write your module in.
In untyped racket, (set the first line to #lang typed/racket/no-check), it is much slower. 36 seconds to create the matrix instead 70 milliseconds. Also as a side not you can run 'raco make matrix.rkt', and this will typecheck and compile the code so that 'racket matrix.rkt' will do less work at startup. On Sat, May 10, 2014 at 9:09 PM, Eduardo Costa <edu50...@gmail.com> wrote: > 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: > > #lang typed/racket ; file: matrix.rkt > (require math/matrix) > > (: mx Index) > (define mx 600) > > (: r (Index Index -> Flonum)) > (define (r i j) (random)) > > (: A : (Matrix Flonum)) > (define A (build-matrix mx mx r)) > > (: sum : Integer Integer -> Flonum) > (define (sum i n) > (let loop ((j 0) (acc 0.0)) > (if (>= j mx) acc > (loop (+ j 1) (+ acc (matrix-ref A i j))) ))) > > (: b : (Matrix Flonum)) > (define b (build-matrix mx 1 sum)) > > (let [(m (matrix-solve A b))] > (displayln (matrix-ref m 0 0))) > > You can run it thus: > > time racket matrix.rkt > > What should I do to speedup the above code? > > ____________________ > Racket Users list: > http://lists.racket-lang.org/users > ____________________ Racket Users list: http://lists.racket-lang.org/users