# HG changeset patch # User Chris Cannam # Date 1369069904 -3600 # Node ID 586d46f649024ab187884762009b4d46ac898b4b # Parent ce4de16ea65dcae527c2b40f7d5941455822cae6 Add speed tests diff -r ce4de16ea65d -r 586d46f64902 yetilab/matrix/test/speedtest.yeti --- /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)); + +();