changeset 248:586d46f64902 sparse

Add speed tests
author Chris Cannam
date Mon, 20 May 2013 18:11:44 +0100
parents ce4de16ea65d
children 1ea5bf6e76b6
files yetilab/matrix/test/speedtest.yeti
diffstat 1 files changed, 134 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yetilab/matrix/test/speedtest.yeti	Mon May 20 18:11:44 2013 +0100
@@ -0,0 +1,134 @@
+
+program yetilab.matrix.test.speedtest;
+
+mat = load yetilab.matrix.matrix;
+vec = load yetilab.vector.vector;
+
+time f =
+   (start = System#currentTimeMillis();
+    result = f ();
+    end = System#currentTimeMillis();
+    println " \(end-start)ms";
+    result);
+
+makeMatrices sz sparsity =
+   (print "Making \(sz) * \(sz) random matrix...";
+    m = time \(mat.randomMatrix { rows = sz, columns = sz });
+    makeSparse () = 
+       (print "Making \(sparsity * 100)% sparse version (as dense matrix)...";
+        t = time \(mat.thresholded sparsity m);
+        println "(Reported density: \(mat.density t))";
+        print "Converting to sparse matrix...";
+        s = time \(mat.toSparse t);
+        println "(Reported density: \(mat.density s))";
+        s);
+    s = makeSparse ();
+    println "Making types:";
+    print "Col-major dense...";
+    cmd = time \(mat.toColumnMajor m);
+    print "Row-major dense...";
+    rmd = time \(mat.toRowMajor m);
+    print "Col-major sparse...";
+    cms = time \(mat.toColumnMajor s);
+    print "Row-major sparse...";
+    rms = time \(mat.toRowMajor s);
+    println "";
+    { cmd, rmd, cms, rms });
+
+println "\nR * M multiplies:\n";
+
+sz = 2000;
+
+{ cmd, rmd, cms, rms } = makeMatrices sz 0.98;
+
+row = mat.newRowVector (vec.fromList (map \(Math#random()) [1..sz]));
+col = mat.newColumnVector (vec.fromList (map \(Math#random()) [1..sz]));
+
+print "R * CMD... ";
+\() (time \(mat.product row cmd));
+
+print "R * RMD... ";
+\() (time \(mat.product row rmd));
+
+print "R * CMS... ";
+\() (time \(mat.product row cms));
+
+print "R * RMS... ";
+\() (time \(mat.product row rms));
+
+println "\nM * C multiplies:\n";
+
+print "CMD * C... ";
+\() (time \(mat.product cmd col));
+
+print "RMD * C... ";
+\() (time \(mat.product rmd col));
+
+print "CMS * C... ";
+\() (time \(mat.product cms col));
+
+print "RMS * C... ";
+\() (time \(mat.product rms col));
+
+
+println "\nM * M multiplies:\n";
+
+sz = 500;
+
+{ cmd, rmd, cms, rms } = makeMatrices sz 0.98;
+
+print "CMD * CMD... ";
+\() (time \(mat.product cmd cmd));
+
+print "CMD * RMD... ";
+\() (time \(mat.product cmd rmd));
+
+print "RMD * CMD... ";
+\() (time \(mat.product rmd cmd));
+
+print "RMD * RMD... ";
+\() (time \(mat.product rmd rmd));
+
+println "";
+
+print "CMS * CMD... ";
+\() (time \(mat.product cms cmd));
+
+print "CMS * RMD... ";
+\() (time \(mat.product cms rmd));
+
+print "RMS * CMD... ";
+\() (time \(mat.product rms cmd));
+
+print "RMS * RMD... ";
+\() (time \(mat.product rms rmd));
+
+println "";
+
+print "CMD * CMS... ";
+\() (time \(mat.product cmd cms));
+
+print "CMD * RMS... ";
+\() (time \(mat.product cmd rms));
+
+print "RMD * CMS... ";
+\() (time \(mat.product rmd cms));
+
+print "RMD * RMS... ";
+\() (time \(mat.product rmd rms));
+
+println "";
+
+print "CMS * CMS... ";
+\() (time \(mat.product cms cms));
+
+print "CMS * RMS... ";
+\() (time \(mat.product cms rms));
+
+print "RMS * CMS... ";
+\() (time \(mat.product rms cms));
+
+print "RMS * RMS... ";
+\() (time \(mat.product rms rms));
+
+();