1 8 9 package org.lsmp.djepExamples; 10 import org.nfunk.jep.*; 11 import org.lsmp.djep.matrixJep.*; 12 import org.lsmp.djep.vectorJep.*; 13 14 18 public class MatrixSpeed { 19 static MatrixJep mj; 20 static VectorJep vj; 21 static int num_itts = 100000; 24 public static void main(String args[]) { 25 long t1 = System.currentTimeMillis(); 26 initVec(); 27 long t2 = System.currentTimeMillis(); 28 System.out.println("Vec initialise "+(t2-t1)); 29 initMat(); 30 long t3 = System.currentTimeMillis(); 31 System.out.println("Mat initialise "+(t3-t2)); 32 33 doBoth("y=[[1,2,3],[3,4,5],[6,7,8]]","y*y"); 34 doBoth("y=[[1,2,3],[3,4,5],[6,7,8]]","y+y"); 35 doBoth("y=[[1,2,3],[3,4,5],[6,7,8]]","y-y"); 36 doBoth("y=[[1,2,3],[3,4,5],[6,7,8]]","y*y+y"); 37 doBoth("y=[1,2,3]","y+y"); 38 doBoth("y=[1,2,3]","y . y"); 39 doBoth("y=[1,2,3]","y^^y"); 40 } 41 42 public static void doBoth(String eqn1,String eqn2) 43 { 44 System.out.println("Testing speed for <"+eqn1+"> and <"+eqn2+">"); 45 doVec(eqn1,eqn2); 46 doMat(eqn1,eqn2); 47 } 48 static void initVec() 49 { 50 vj = new VectorJep(); 51 vj.addStandardConstants(); 52 vj.addStandardFunctions(); 53 vj.addComplex(); 54 vj.setAllowUndeclared(true); 55 vj.setImplicitMul(true); 56 vj.setAllowAssignment(true); 57 } 58 59 static void doVec(String eqn1,String eqn2) 60 { 61 try 63 { 64 Node node1 = vj.parse(eqn1); 65 vj.evaluate(node1); 66 Node node = vj.parse(eqn2); 67 long t1 = System.currentTimeMillis(); 68 for(int i=0;i<num_itts;++i) 70 vj.evaluate(node); 71 long t2 = System.currentTimeMillis(); 72 System.out.println("Using VectorJep :"+(t2-t1)); 73 } 74 catch(Exception e) {System.out.println("Error"+e.getMessage());} 75 } 76 77 static void initMat() 78 { 79 mj = new MatrixJep(); 80 mj.addStandardConstants(); 81 mj.addStandardFunctions(); 82 mj.addComplex(); 83 mj.setAllowUndeclared(true); 84 mj.setImplicitMul(true); 85 mj.setAllowAssignment(true); 86 } 87 88 static void doMat(String eqn1, String eqn2) 89 { 90 try 91 { 92 Node node2 = mj.simplify(mj.preprocess(mj.parse(eqn1))); 93 mj.evaluate(node2); 94 Node node3 = mj.simplify(mj.preprocess(mj.parse(eqn2))); 95 long t1 = System.currentTimeMillis(); 96 for(int i=0;i<num_itts;++i) 98 mj.evaluateRaw(node3); 99 long t2 = System.currentTimeMillis(); 100 System.out.println("Using MatrixJep :"+(t2-t1)); 101 } 102 catch(Exception e) {System.out.println("Error"+e.getMessage());} 103 } 104 } 105 | Popular Tags |