org.lsmp.djepExamples.MRpSpeed Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jep Show documentation
Show all versions of jep Show documentation
JEP is a Java library for parsing and evaluating mathematical expressions.
The newest version!
/* @author rich
* Created on 26-Feb-2004
*/
package org.lsmp.djepExamples;
import org.nfunk.jep.*;
import org.lsmp.djep.matrixJep.*;
import org.lsmp.djep.mrpe.MRpCommandList;
import org.lsmp.djep.mrpe.MRpEval;
import org.lsmp.djep.vectorJep.*;
/**
* Compares the speed of matrix operations
* using mrpe, vectorJep and matrixJep.
*/
public class MRpSpeed {
static MatrixJep mj;
static VectorJep vj;
static int num_itts = 100000; // for normal use
// static int num_itts = 1000; // for use with profiler
public static void main(String args[]) {
if(args.length>0)
num_itts = Integer.parseInt(args[0]);
System.out.println("VectorJep, MatrixJep, MRPEval Speed comparison");
System.out.println("Number of iterations: "+num_itts);
long t1 = System.currentTimeMillis();
initVec();
long t2 = System.currentTimeMillis();
System.out.println("Vec initialise "+(t2-t1));
initMat();
long t3 = System.currentTimeMillis();
System.out.println("Mat initialise "+(t3-t2));
doRawAdd();
doObjAdd();
doRawMult();
doObjMult();
doAll(new String[]{"y=[[1,2,3],[4,5,6],[7,8,9]]"},"y*y");
doAll(new String[]{},"y=[[1,2,3],[4,5,6],[7,8,9]]");
doAll(new String[]{"y=[[1,2,3],[4,5,6],[7,8,9]]"},"z=y*y");
doAll(new String[0],"[[1,2,3],[4,5,6],[7,8,9]]*[[1,2,3],[4,5,6],[7,8,9]]");
doAll(new String[]{"y=[[1,2,3],[4,5,6],[7,8,9]]"},"y+y");
doAll(new String[]{"y=[[1,2,3],[4,5,6],[7,8,9]]"},"y-y");
doAll(new String[]{"y=[[1,2,3],[4,5,6],[7,8,9]]"},"y*y+y");
doAll(new String[]{"x=[1,2,3]","y=[[1,2,3],[4,5,6],[7,8,9]]"},"x*y");
doAll(new String[]{"x=[1,2,3]","y=[[1,2,3],[4,5,6],[7,8,9]]"},"y*x");
doAll(new String[]{"y=[1,2,3]"},"y+y");
doAll(new String[]{"y=[1,2,3]"},"y . y");
doAll(new String[]{"y=[1,2,3]"},"y^^y");
doAll(new String[]{"y=[[1,2],[3,4]]"},"y*y");
doAll(new String[]{"y=[[1,2],[3,4]]"},"y+y");
doAll(new String[]{"y=[[1,2],[3,4]]"},"y-y");
doAll(new String[]{"y=[[1,2],[3,4]]"},"y*y+y");
doAll(new String[]{"x=[1,2]","y=[[1,2],[3,4]]"},"x*y");
doAll(new String[]{"x=[1,2]","y=[[1,2],[3,4]]"},"y*x");
doAll(new String[0],"1*2*3+4*5*6+7*8*9");
doAll(new String[]{"x1=1","x2=2","x3=3","x4=4","x5=5","x6=6","x7=7","x8=8","x9=9"},
"x1*x2*x3+x4*x5*x6+x7*x8*x9");
doAll(new String[]{"y=[1,2,3,4,5]"},"y+y");
doAll(new String[]{"y=[[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20],[21,22,23,24,25]]"},"y*y");
doAll(new String[]{"x=0.7"},"cos(x)^2+sin(x)^2");
for(int scale=2;scale<=6;++scale) {
StringBuffer sb = new StringBuffer("y=[");
int k=1;
for(int i=0;i0) sb.append(',');
sb.append('[');
for(int j=0;j0) sb.append(',');
sb.append(k);
++k;
}
sb.append(']');
}
sb.append(']');
doAll(new String[]{sb.toString()},"y*y");
}
}
public static void doAll(String eqns[],String eqn2)
{
System.out.println("Testing speed for <"+eqn2+"> Where ");
for(int i=0;i