[plt-scheme] Vector / matrix benchmarks

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Wed Sep 6 11:21:36 EDT 2006

Noel Welsh skrev:
> Someone asked about the speed of vector operations in PLT
> Scheme.  Below are some benchmarks testing the speed of a
> 20x20 matrix multiplication using a variety of different
> representations.
> 
> Results are basically
> 
> Galore table >>> array >> srfi-4 vector > vector > c array

This makes sense: flexibility has a cost.

Here is another data point, namely extensible vectors, which grows
automatically.


<http://ja.soegaard.net/planet/html/soegaard/evector.plt/current/extensible-vector.txt>


(require (planet "evector.scm" ("soegaard" "evector.plt"))
          (lib "42.ss" "srfi"))

(define-syntax evector-ec
   (syntax-rules ()
     ((evector-ec etc1 etc ...)
      (list->evector (list-ec etc1 etc ...)) )))

(define vector-matrix
   (vector-ec
    (:range x 0 20)
    (:range y 0 20)
    (* x y)))

(define evector-matrix
   (evector-ec
    (:range x 0 20)
    (:range y 0 20)
    (* x y)))

(define (vector-multiply)
   (sum-ec
    (:range row 0 20)
    (:range col 0 20)
    (:range elt 0 20)
    (* (vector-ref vector-matrix (+ (* row 20) elt))
       (vector-ref vector-matrix (+ (* elt 20) col)))))

(define (evector-multiply)
   (sum-ec
    (:range row 0 20)
    (:range col 0 20)
    (:range elt 0 20)
    (* (evector-ref evector-matrix (+ (* row 20) elt))
       (evector-ref evector-matrix (+ (* elt 20) col)))))

(time (evector-multiply))
(time (vector-multiply))


-- 
Jens Axel Søgaard



Posted on the users mailing list.