/** * Performance test: Creating arguments: Iteration: * Argument x = new Argument("x", 5) * * @param test * @param testId */ static void test015(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Creating arguments: Iteration: Argument x = new Argument(\"x\", 5)"; test.iterNum = 1000000; test.exprStr = "Argument x = new Argument(\"x\", 5)"; Argument x = new Argument("x", 2); test.testInit(); for (int i = 0; i <= test.iterNum; i++) { x = new Argument("x", 5); } test.testClose(); x.getArgumentValue(); }
/** * Performance test: Creating constants: Iteration: * Constant c = new Constant("c=5") * * @param test * @param testId */ static void test014(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Creating constants: Iteration: Constant c = new Constant(\"c=5\")"; test.iterNum = 100000; test.exprStr = "Constant c = new Constant(\"c=5\")"; Constant c = new Constant("c", 5); test.testInit(); for (int i = 0; i <= test.iterNum; i++) { c = new Constant("c=5"); } test.testClose(); c.getConstantValue(); }
/** * Performance test: Creating expressions + checking syntax: * Iteration: * Expression e = new Expression("sin(2+(3*4)^2)/10") * * @param test * @param testId */ static void test020(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Creating expressions + checking syntax: Iteration: Expression e = new Expression(\"sin(2+(3*4)^2)/10\")"; test.iterNum = 100000; test.exprStr = "Expression e = new Expression(\"sin(2+(3*4)^2)/10\")"; Expression e = new Expression(""); test.testInit(); for (int i = 0; i <= test.iterNum; i++) { e = new Expression("sin(2+(3*4)^2)/10"); e.checkSyntax(); } test.testClose(); e.calculate(); }
public static void test001(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Simple calculations - multiplication. Expression created once. Iteration: repeatedly recalculated same expression."; test.iterNum = 20000000; test.exprStr = "2*3"; Expression e = new Expression(test.exprStr); test.testInit(); for (int i = 0; i <= test.iterNum; i++) { e.calculate(); } test.testClose(); }
/** * Performance test: Simple calculations - addition with * argument. Expression created once, containing argument * 'x'. Iteration: argument value is being modified * (increased), then expression is recalculated * * @param test * @param testId */ static void test011(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Simple calculations - addition with argument. Expression created once, containing argument 'x'. Iteration: argument value is being modified (increased), then expression is recalculated"; test.iterNum = 20000000; test.exprStr = "2+x"; Argument x = new Argument("x"); Expression e = new Expression(test.exprStr, x); test.testInit(); for (int i = 0; i <= test.iterNum; i++) { x.setArgumentValue(i); e.calculate(); } test.testClose(); }
public static void test010(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Combination of different operations. Expression created once. Iteration: repeatedly recalculated same expression."; test.iterNum = 20000000; test.exprStr = "sin(2+(3*4)^2)/10"; Expression e = new Expression(test.exprStr); test.testInit(); for (int i = 0; i <= test.iterNum; i++) { e.calculate(); } test.testClose(); }
public static void test018(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Creating functions: Iteration: Function f = new Function(\"f(x,y)=x+y\")"; test.iterNum = 100000; test.exprStr = "Function f = new Function(\"f(x,y)=x+y\")"; Function f = new Function("f", "x", "x"); test.testInit(); for (int i = 0; i <= test.iterNum; i++) { f = new Function("f(x,y)=x+y"); } test.testClose(); f.calculate(1); }
/** * Performance test: User defined function f(x,y)=3x+4y. * Expression &Function created once, containing argument 'x'. * Iteration: argument value is being modified (increased), * then expression is recalculated * * @param test * @param testId */ static void test012(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "User defined function f(x,y)=3*x+4*y. Expression &Function created once, containing argument 'x'. Iteration: argument value is being modified (increased), then expression is recalculated"; test.iterNum = 2000000; test.exprStr = "3*f(x,y)-(2*x+3*y)"; Argument x = new Argument("x"); Argument y = new Argument("y"); Function f = new Function("f(x,y)=3*x+4*y"); Expression e = new Expression(test.exprStr, f, x, y); test.testInit(); for (int i = 0; i <= test.iterNum; i++) { x.setArgumentValue(i); y.setArgumentValue(i); e.calculate(); } test.testClose(); }
/** * Creates threads, executes them, then wait till * each thread is finished * * @param test Test definition * @param classId Class id specifying the implementation of test scenario */ static void createRunJoinThreads(PerformanceTestResult test, int classId) { test.testInit(); TestThread[] runners = new TestThread[test.threadsNum]; #if !PCL && !NETSTANDARD1_0 && !NETSTANDARD1_1 && !NETSTANDARD1_2 && !NETSTANDARD1_3 && !NETSTANDARD1_4 && !NETSTANDARD1_5 && !NETSTANDARD1_6 Thread[] threads = new Thread[test.threadsNum]; #endif for (int threadId = 0; threadId < test.threadsNum; threadId++) { switch (classId) { case 0: runners[threadId] = new TestSimpleCalcThread(test); break; case 1: runners[threadId] = new TestSimpleCalcThread(test); break; case 2: runners[threadId] = new TestSimpleCalcThread(test); break; case 3: runners[threadId] = new TestSimpleCalcThread(test); break; case 4: runners[threadId] = new TestSimpleCalcThread(test); break; case 5: runners[threadId] = new TestSimpleCalcThread(test); break; case 6: runners[threadId] = new TestSimpleCalcThread(test); break; case 7: runners[threadId] = new TestSimpleCalcThread(test); break; case 8: runners[threadId] = new TestSimpleCalcThread(test); break; case 9: runners[threadId] = new TestSimpleCalcThread(test); break; case 10: runners[threadId] = new TestSimpleCalcThread(test); break; case 11: runners[threadId] = new Test011Thread(test); break; case 12: runners[threadId] = new Test012Thread(test); break; case 13: runners[threadId] = new Test013Thread(test); break; case 14: runners[threadId] = new Test014Thread(test); break; case 15: runners[threadId] = new Test015Thread(test); break; case 16: runners[threadId] = new Test016Thread(test); break; case 17: runners[threadId] = new Test017Thread(test); break; case 18: runners[threadId] = new Test018Thread(test); break; case 19: runners[threadId] = new Test019Thread(test); break; case 20: runners[threadId] = new Test020Thread(test); break; } #if PCL || NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 || NETSTANDARD1_6 || NETCOREAPP1_0 || NETCOREAPP1_1 runners[threadId].run(); #else threads[threadId] = new Thread(runners[threadId].run); threads[threadId].Start(); #endif } #if !PCL && !NETSTANDARD1_0 && !NETSTANDARD1_1 && !NETSTANDARD1_2 && !NETSTANDARD1_3 && !NETSTANDARD1_4 && !NETSTANDARD1_5 && !NETSTANDARD1_6 && NETCOREAPP1_0 && NETCOREAPP1_1 for (int threadId = 0; threadId < test.threadsNum; threadId++) { try { threads[threadId].Join(); } catch (ThreadInterruptedException e) { mXparser.consolePrintln(e.StackTrace); } } #endif test.testClose(); }
/** * Default constructor - creates parameters * for a single test thread * * @param test Test parameters * @param threadsNum Number of threads */ internal TestThread(PerformanceTestResult test) { this.test = test; this.iterNum = test.iterNum / test.threadsNum; }
internal TestSimpleCalcThread(PerformanceTestResult test) : base(test) { }
internal Test020Thread(PerformanceTestResult test) : base(test) { }
/** * Performance test: Creating functions: Iteration: * Function f = new Function("f(x,y)=x+y") * * @param test * @param testId */ static void test018(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Creating functions: Iteration: Function f = new Function(\"f(x,y)=x+y\")"; test.iterNum = 100000; test.exprStr = "Function f = new Function(\"f(x,y)=x+y\")"; createRunJoinThreads(test, 18); }
/** * Performance test: Creating expressions + checking syntax: * Iteration: * Expression e = new Expression("sin(2+(3*4)^2)/10") * * @param test * @param testId */ static void test020(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Creating expressions + checking syntax: Iteration: Expression e = new Expression(\"sin(2+(3*4)^2)/10\")"; test.iterNum = 100000; test.exprStr = "Expression e = new Expression(\"sin(2+(3*4)^2)/10\")"; createRunJoinThreads(test, 20); }
/** * Starts mXparser performance tests. List of performed tests: * * <ul> * <li>00. Simple calculations - addition. Expression created once. Iteration: repeatedly recalculated same expression. * <li>01. Simple calculations - multiplication. Expression created once. Iteration: repeatedly recalculated same expression. * <li>02. Simple calculations - division. Expression created once. Iteration: repeatedly recalculated same expression. * <li>03. Simple calculations - power. Expression created once. Iteration: repeatedly recalculated same expression. * <li>04. Simple calculations - sinus. Expression created once. Iteration: repeatedly recalculated same expression. * <li>05. Simple calculations - 2 additions. Expression created once. Iteration: repeatedly recalculated same expression. * <li>06. Simple calculations - 3 additions. Expression created once. Iteration: repeatedlyrecalculated same expression. * <li>07. Simple calculations - 3 additions + 1 parenthesis. Expression created once. Iteration: repeatedly recalculated same expression. * <li>08. Simple calculations - 3 additions + 2 brackets. Expression created once. Iteration: repeatedly recalculated same expression. * <li>09. Simple calculations - 3 additions + 2 brackets. Expression created once. Iteration: repeatedly recalculated same expression. * <li>10. Combination of different operations. Expression created once. Iteration: repeatedly recalculated same expression. * <li>11. Simple calculations - addition with argument. Expression created once, containing argument 'x'. Iteration: argument value is being modified (increased), then expression is recalculated * <li>12. User defined function f(x,y)=3x+4y. Expression &Function created once, containing argument 'x'. Iteration: argument value is being modified (increased), then expression is recalculated * <li>13. Creating constants: Iteration: Constant c = new Constant("c", 5) * <li>14. Creating constants: Iteration: Constant c = new Constant("c=5") * <li>15. Creating arguments: Iteration: Argument x = new Argument("x", 5) * <li>16. Creating arguments: Iteration: Argument x = new Argument("x=5") * <li>17. Creating functions: Iteration: Function f = new Function("f", "x+y", "x", "y") * <li>18. Creating functions: Iteration: Function f = new Function("f(x,y)=x+y") * <li>19. Creating expressions: Iteration: Expression e = new Expression("sin(2+(3*4)^2)/10") * <li>20. Creating expressions + checking syntax: Iteration: Expression e = new Expression("sin(2+(3*4)^2)/10") * </ul> * * @param threadsNum Number of threads * @return Number of tests that were not performed. */ public static int Start(int threadsNum) { if (threadsNum <= 0) threadsNum = mXparser.getThreadsNumber(); tests = new PerformanceTestResult[100]; int testId = -1; int lastTestId = 20; tests[++testId] = new PerformanceTestResult(threadsNum); test000(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test001(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test002(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test003(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test004(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test005(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test006(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test007(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test008(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test009(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test010(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test011(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test012(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test013(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test014(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test015(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test016(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test017(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test018(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test019(tests[testId], testId); tests[++testId] = new PerformanceTestResult(threadsNum); test020(tests[testId], testId); return lastTestId - testId; }
/** * Default constructor - creates parameters * for a single test thread * * @param test Test parameters * @param threadsNum Number of threads */ internal TestThread(PerformanceTestResult test) { this.test = test; this.iterNum = test.iterNum/test.threadsNum; }
/** * Performance test: Simple calculations - addition with * argument. Expression created once, containing argument * 'x'. Iteration: argument value is being modified * (increased), then expression is recalculated * * @param test * @param testId */ static void test011(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Simple calculations - addition with argument. Expression created once, containing argument 'x'. Iteration: argument value is being modified (increased), then expression is recalculated"; test.iterNum = 20000000; test.exprStr = "2+x"; createRunJoinThreads(test, 11); }
internal Test019Thread(PerformanceTestResult test) : base(test) { }
/** * Performance test: Combination of different operations. * Expression created once. Iteration: repeatedly * recalculated same expression. * * @param test * @param testId */ static void test010(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Combination of different operations. Expression created once. Iteration: repeatedly recalculated same expression."; test.iterNum = 20000000; test.exprStr = "sin(2+(3*4)^2)/10"; createRunJoinThreads(test, 10); }
/** * Performance test: Simple calculations - 3 additions + 2 * brackets. Expression created once. Iteration: * repeatedly recalculated same expression. * * @param test * @param testId */ static void test009(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Simple calculations - 3 additions + 2 brackets. Expression created once. Iteration: repeatedly recalculated same expression."; test.iterNum = 20000000; test.exprStr = "2+(3+(4+5))"; createRunJoinThreads(test, 9); }
/** * Performance test: Simple calculations - 3 additions + * 1 parenthesis. Expression created once. Iteration: * repeatedly recalculated same expression. * * @param test * @param testId */ static void test007(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Simple calculations - 3 additions + 1 parenthesis. Expression created once. Iteration: repeatedly recalculated same expression."; test.iterNum = 20000000; test.exprStr = "2+(3+4)+5"; createRunJoinThreads(test, 7); }
/** * Performance test: Simple calculations - 2 additions. * Expression created once. Iteration: repeatedly recalculated * same expression. * * @param test * @param testId */ static void test005(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Simple calculations - 2 additions. Expression created once. Iteration: repeatedly recalculated same expression."; test.iterNum = 20000000; test.exprStr = "2+3+4"; createRunJoinThreads(test, 5); }
/** * Creates threads, executes them, then wait till * each thread is finished * * @param test Test definition * @param classId Class id specifying the implementation of test scenario */ static void createRunJoinThreads(PerformanceTestResult test, int classId) { test.testInit(); TestThread[] runners = new TestThread[test.threadsNum]; Thread[] threads = new Thread[test.threadsNum]; for (int threadId = 0; threadId < test.threadsNum; threadId++) { switch (classId) { case 0: runners[threadId] = new TestSimpleCalcThread(test); break; case 1: runners[threadId] = new TestSimpleCalcThread(test); break; case 2: runners[threadId] = new TestSimpleCalcThread(test); break; case 3: runners[threadId] = new TestSimpleCalcThread(test); break; case 4: runners[threadId] = new TestSimpleCalcThread(test); break; case 5: runners[threadId] = new TestSimpleCalcThread(test); break; case 6: runners[threadId] = new TestSimpleCalcThread(test); break; case 7: runners[threadId] = new TestSimpleCalcThread(test); break; case 8: runners[threadId] = new TestSimpleCalcThread(test); break; case 9: runners[threadId] = new TestSimpleCalcThread(test); break; case 10: runners[threadId] = new TestSimpleCalcThread(test); break; case 11: runners[threadId] = new Test011Thread(test); break; case 12: runners[threadId] = new Test012Thread(test); break; case 13: runners[threadId] = new Test013Thread(test); break; case 14: runners[threadId] = new Test014Thread(test); break; case 15: runners[threadId] = new Test015Thread(test); break; case 16: runners[threadId] = new Test016Thread(test); break; case 17: runners[threadId] = new Test017Thread(test); break; case 18: runners[threadId] = new Test018Thread(test); break; case 19: runners[threadId] = new Test019Thread(test); break; case 20: runners[threadId] = new Test020Thread(test); break; } threads[threadId] = new Thread(runners[threadId].run); threads[threadId].Start(); } for (int threadId = 0; threadId < test.threadsNum; threadId++) try { threads[threadId].Join(); } catch (ThreadInterruptedException e) { Console.WriteLine(e.StackTrace); } test.testClose(); }
/** * Performance test: Creating constants: Iteration: * Constant c = new Constant("c=5") * * @param test * @param testId */ static void test014(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Creating constants: Iteration: Constant c = new Constant(\"c=5\")"; test.iterNum = 100000; test.exprStr = "Constant c = new Constant(\"c=5\")"; createRunJoinThreads(test, 14); }
/** * Performance test: Creating arguments: Iteration: * Argument x = new Argument("x", 5) * * @param test * @param testId */ static void test016(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "Creating arguments: Iteration: Argument x = new Argument(\"x=5\")"; test.iterNum = 100000; test.exprStr = "Argument x = new Argument(\"x=5\")"; createRunJoinThreads(test, 16); }
/** * Performance test: User defined function f(x,y)=3x+4y. * Expression &Function created once, containing argument 'x'. * Iteration: argument value is being modified (increased), * then expression is recalculated * * @param test * @param testId */ static void test012(PerformanceTestResult test, int testId) { test.Id = testId; test.description = "User defined function f(x,y)=3*x+4*y. Expression &Function created once, containing argument 'x'. Iteration: argument value is being modified (increased), then expression is recalculated"; test.iterNum = 2000000; test.exprStr = "3*f(x,y)-(2*x+3*y)"; createRunJoinThreads(test, 12); }
/** * Creates threads, executes them, then wait till * each thread is finished * * @param test Test definition * @param classId Class id specifying the implementation of test scenario */ static void createRunJoinThreads(PerformanceTestResult test, int classId) { test.testInit(); TestThread[] runners = new TestThread[test.threadsNum]; Thread[] threads = new Thread[test.threadsNum]; for (int threadId = 0; threadId < test.threadsNum; threadId++) { switch (classId) { case 0: runners[threadId] = new TestSimpleCalcThread(test); break; case 1: runners[threadId] = new TestSimpleCalcThread(test); break; case 2: runners[threadId] = new TestSimpleCalcThread(test); break; case 3: runners[threadId] = new TestSimpleCalcThread(test); break; case 4: runners[threadId] = new TestSimpleCalcThread(test); break; case 5: runners[threadId] = new TestSimpleCalcThread(test); break; case 6: runners[threadId] = new TestSimpleCalcThread(test); break; case 7: runners[threadId] = new TestSimpleCalcThread(test); break; case 8: runners[threadId] = new TestSimpleCalcThread(test); break; case 9: runners[threadId] = new TestSimpleCalcThread(test); break; case 10: runners[threadId] = new TestSimpleCalcThread(test); break; case 11: runners[threadId] = new Test011Thread(test); break; case 12: runners[threadId] = new Test012Thread(test); break; case 13: runners[threadId] = new Test013Thread(test); break; case 14: runners[threadId] = new Test014Thread(test); break; case 15: runners[threadId] = new Test015Thread(test); break; case 16: runners[threadId] = new Test016Thread(test); break; case 17: runners[threadId] = new Test017Thread(test); break; case 18: runners[threadId] = new Test018Thread(test); break; case 19: runners[threadId] = new Test019Thread(test); break; case 20: runners[threadId] = new Test020Thread(test); break; } threads[threadId] = new Thread(runners[threadId].run); threads[threadId].Start(); } for (int threadId = 0; threadId < test.threadsNum; threadId++) { try { threads[threadId].Join(); } catch (ThreadInterruptedException e) { Console.WriteLine(e.StackTrace); } } test.testClose(); }