001: package org.mvel.tests.perftests;
002:
003: import ognl.Ognl;
004: import org.apache.commons.el.ExpressionEvaluatorImpl;
005: import org.mvel.MVEL;
006: import org.mvel.tests.main.res.Base;
007: import org.mvel.tests.main.res.Foo;
008:
009: import javax.servlet.jsp.el.Expression;
010: import javax.servlet.jsp.el.VariableResolver;
011: import static java.lang.Integer.parseInt;
012: import static java.lang.System.currentTimeMillis;
013: import java.math.BigDecimal;
014: import java.math.RoundingMode;
015: import java.util.ArrayList;
016: import java.util.HashMap;
017: import java.util.List;
018: import java.util.Map;
019:
020: /**
021: * Performance Tests Comparing MVEL to OGNL with Same Expressions.
022: */
023: public class ELComparisons implements Runnable {
024: private final Base baseClass = new Base();
025:
026: public static int RUN_MVEL = 1;
027: public static int RUN_OGNL = 1 << 1;
028: public static int RUN_COMMONS_EL = 1 << 2;
029: public static int RUN_JAVA_NATIVE = 1 << 3;
030: // public static int RUN_GROOVY = 1 << 4;
031:
032: private static int COMPILED = 1 << 30;
033: private static int INTERPRETED = 1 << 31;
034:
035: private static int ALL = RUN_MVEL + RUN_OGNL + RUN_COMMONS_EL
036: + RUN_JAVA_NATIVE;
037:
038: private static final int TESTNUM = 100000;
039: private static final int TESTITER = 3;
040:
041: private long ognlTotal = 0;
042: private long mvelTotal = 0;
043: private long commonElTotal = 0;
044: private long javaNativeTotal = 0;
045: private long groovyTotal = 0;
046:
047: private int testFlags = 0;
048:
049: private boolean silent = false;
050:
051: private static List<PerfTest> tests = new ArrayList<PerfTest>();
052:
053: private final static Map<String, Object> variables = new HashMap<String, Object>();
054:
055: static {
056: NativeTest nt;
057:
058: // nt = new NativeTest() {
059: //
060: // public Object run(Object baseClass, Map vars) {
061: // return "Hello World";
062: // }
063: // };
064: //
065: // tests.add(new PerfTest("Simple String Pass-Through", "'Hello World'", ALL, nt));
066:
067: nt = new NativeTest() {
068:
069: public Object run(Object baseClass, Map vars) {
070: return vars.get("data");
071: }
072: };
073:
074: // tests.add(new PerfTest("Shallow Property", "data", ALL, nt));
075:
076: nt = new NativeTest() {
077: public Object run(Object baseClass, Map vars) {
078: return ((Base) baseClass).getFoo().getBar().getName();
079: }
080: };
081:
082: tests
083: .add(new PerfTest("Deep Property", "foo.bar.name", ALL,
084: nt));
085: tests.add(new PerfTest("Static Field Access (MVEL)",
086: "Integer.MAX_VALUE", RUN_MVEL, nt));
087: tests.add(new PerfTest("Static Field Access (OGNL)",
088: "@java.lang.Integer@MAX_VALUE", RUN_OGNL, nt));
089: tests.add(new PerfTest("Inline Array Creation (MVEL)",
090: "{'foo', 'bar'}", RUN_MVEL, nt));
091: tests.add(new PerfTest("Inline Array Creation (OGNL)",
092: "new String[] {'foo', 'bar'}", RUN_OGNL, nt));
093:
094: nt = new NativeTest() {
095: public Object run(Object baseClass, Map vars) {
096: return ((Foo) ((Base) baseClass).funMap.get("foo"))
097: .happy();
098: }
099: };
100:
101: nt = new NativeTest() {
102:
103: public Object run(Object baseClass, Map vars) {
104: return 10 + 1 - 1;
105: }
106: };
107:
108: // tests.add(new PerfTest("Collection Access + Method Call", "funMap['foo'].happy()", RUN_MVEL + RUN_OGNL + RUN_JAVA_NATIVE, nt));
109: // tests.add(new PerfTest("Boolean compare", "data == 'cat'", ALL));
110: // tests.add(new PerfTest("Object instantiation", "new String('Hello')", RUN_OGNL + RUN_MVEL));
111: // tests.add(new PerfTest("Method access", "readBack('this is a string')", RUN_OGNL + RUN_MVEL));
112: // tests.add(new PerfTest("Arithmetic", "10 + 1 - 1", ALL, nt));
113: }
114:
115: public ELComparisons() {
116: variables.put("data", baseClass.data);
117: variables.put("foo", baseClass.foo);
118: variables.put("funMap", baseClass.funMap);
119: }
120:
121: public void setTestFlags(int testFlags) {
122: this .testFlags = testFlags;
123: }
124:
125: public static void main(String[] args) throws Exception {
126: ELComparisons omc = new ELComparisons();
127: boolean multithreaded = false;
128: boolean compiled = true;
129: boolean interpreted = true;
130: boolean continuous = false;
131: boolean silent = false;
132: long totaltime = 0;
133:
134: int threadMax = 1;
135:
136: if (args != null) {
137: for (int i = 0; i < args.length; i++) {
138: if (args[i].equals("-continuous"))
139: continuous = true;
140: else if (args[i].equals("-threaded")) {
141: if ((i + 1) == args.length) {
142: throw new RuntimeException(
143: "expected parameter for -threaded (number of threads)");
144: }
145: multithreaded = true;
146: threadMax = parseInt(args[++i]);
147:
148: } else if (args[i].equals("-nocompiled"))
149: compiled = false;
150: else if (args[i].equals("-nointerpret"))
151: interpreted = false;
152: else if (args[i].equals("-silent"))
153: silent = true;
154: }
155:
156: }
157:
158: int flags = (compiled ? COMPILED : 0)
159: + (interpreted ? INTERPRETED : 0);
160:
161: long ognlTotals;
162: long mvelTotals;
163: long commonsElTotals;
164: long javaNativeTotals;
165: long groovyTotals;
166:
167: ELComparisons ognlTests = new ELComparisons();
168: ognlTests.setTestFlags(flags + RUN_OGNL);
169: ognlTests.setSilent(true);
170:
171: ELComparisons mvelTests = new ELComparisons();
172: mvelTests.setTestFlags(flags + RUN_MVEL);
173: mvelTests.setSilent(silent);
174:
175: // ELComparisons groovyTests = new ELComparisons();
176: // groovyTests.setTestFlags(flags + RUN_GROOVY);
177: // groovyTests.setSilent(silent);
178:
179: ELComparisons commonsELTests = new ELComparisons();
180: commonsELTests.setTestFlags(flags + RUN_COMMONS_EL);
181: commonsELTests.setSilent(silent);
182:
183: ELComparisons nativeJavaTests = new ELComparisons();
184: nativeJavaTests.setTestFlags(flags + RUN_JAVA_NATIVE);
185: nativeJavaTests.setSilent(silent);
186:
187: if (multithreaded) {
188: System.out
189: .println("THREADS\tOGNL\tMVEL\tCommons-EL\tNative Java");
190:
191: for (int threadNumber = 1; threadNumber < 100; threadNumber += 5) {
192:
193: totaltime = System.currentTimeMillis();
194:
195: ognlTests.reset();
196:
197: Thread[] threads = new Thread[threadNumber];
198: for (int i = 0; i < threads.length; i++) {
199: threads[i] = new Thread(ognlTests);
200: }
201:
202: for (Thread thread : threads) {
203: thread.run();
204: }
205:
206: for (Thread thread : threads) {
207: thread.join();
208: }
209:
210: ognlTotals = ognlTests.getOgnlTotal();
211:
212: mvelTests.reset();
213:
214: for (int i = 0; i < threads.length; i++) {
215: threads[i] = new Thread(mvelTests);
216: }
217:
218: for (Thread thread : threads) {
219: thread.run();
220: }
221:
222: for (Thread thread : threads) {
223: thread.join();
224: }
225:
226: mvelTotals = mvelTests.getMvelTotal();
227:
228: // groovyTests.reset();
229: //
230: // for (int i = 0; i < threads.length; i++) {
231: // threads[i] = new Thread(groovyTests);
232: // }
233: //
234: // for (Thread thread : threads) {
235: // thread.run();
236: // }
237: //
238: // for (Thread thread : threads) {
239: // thread.join();
240: // }
241: //
242: // groovyTotals = groovyTests.getGroovyTotal();
243:
244: commonsELTests.reset();
245:
246: for (int i = 0; i < threads.length; i++) {
247: threads[i] = new Thread(commonsELTests);
248: }
249:
250: for (Thread thread : threads) {
251: thread.run();
252: }
253:
254: for (Thread thread : threads) {
255: thread.join();
256: }
257:
258: commonsElTotals = commonsELTests.getCommonElTotal();
259:
260: nativeJavaTests.reset();
261:
262: for (int i = 0; i < threads.length; i++) {
263: threads[i] = new Thread(nativeJavaTests);
264: }
265:
266: for (Thread thread : threads) {
267: thread.run();
268: }
269:
270: for (Thread thread : threads) {
271: thread.join();
272: }
273:
274: javaNativeTotals = nativeJavaTests.getJavaNativeTotal();
275:
276: totaltime = System.currentTimeMillis() - totaltime;
277:
278: System.out.println(threadNumber + "\t" + ognlTotals
279: + "\t" + mvelTotals + "\t" + commonsElTotals
280: + "\t" + javaNativeTotals);
281:
282: // System.out.println("\nPerformance Comparison Done. OUTPUT TOTALS:");
283: // System.out.println("Total Number of Threads: " + threadMax);
284: // System.out.println("OGNL Total Runtime (ms): " + ognlTotals);
285: // System.out.println("MVEL Total Runtime (ms): " + mvelTotals);
286: // System.out.println("Commons EL Total Runtime (ms): " + commonsELTests);
287:
288: }
289: System.out.println("Done.");
290:
291: } else {
292: omc.setTestFlags(ALL + INTERPRETED + COMPILED);
293: omc.run();
294: }
295:
296: }
297:
298: public void run() {
299: try {
300:
301: for (PerfTest test : tests) {
302: runTest(test, TESTNUM);
303: }
304: } catch (Exception e) {
305: e.printStackTrace();
306: }
307: }
308:
309: public void runTest(PerfTest test, int count) throws Exception {
310: int exFlags = test.getRunFlags();
311: String expression = test.getExpression();
312: String name = test.getName();
313:
314: if (!silent) {
315: System.out.println("Test Name : "
316: + test.getName());
317: System.out.println("Expression : "
318: + test.getExpression());
319: System.out.println("Iterations : " + count);
320: }
321:
322: long time;
323: long mem;
324: long total = 0;
325: long[] res = new long[TESTITER];
326:
327: if ((testFlags & INTERPRETED) != 0) {
328:
329: if (!silent)
330: System.out.println("Interpreted Results :");
331:
332: if ((testFlags & RUN_OGNL) != 0
333: && ((exFlags & RUN_OGNL)) != 0) {
334: try {
335: // unbenched warm-up
336: for (int i = 0; i < count; i++) {
337: Ognl.getValue(expression, baseClass);
338: }
339:
340: // System.gc();
341:
342: time = currentTimeMillis();
343: mem = Runtime.getRuntime().freeMemory();
344:
345: for (int reps = 0; reps < TESTITER; reps++) {
346: for (int i = 0; i < count; i++) {
347: Ognl.getValue(expression, baseClass);
348: }
349:
350: if (reps == 0)
351: res[0] = total += currentTimeMillis()
352: - time;
353: else
354: res[reps] = (total * -1)
355: + (total += currentTimeMillis()
356: - time - total);
357:
358: }
359:
360: if (!silent)
361: System.out
362: .println("(OGNL) : "
363: + new BigDecimal(
364: ((currentTimeMillis() - time)))
365: .divide(
366: new BigDecimal(
367: TESTITER),
368: 2,
369: RoundingMode.HALF_UP)
370: + "ms avg. (mem delta: "
371: + ((Runtime.getRuntime()
372: .freeMemory() - mem) / 1024)
373: + "kb) " + resultsToString(res));
374: } catch (Exception e) {
375: if (!silent)
376: System.out
377: .println("(OGNL) : <<COULD NOT EXECUTE>>");
378: }
379:
380: }
381:
382: synchronized (this ) {
383: ognlTotal += total;
384: }
385:
386: total = 0;
387:
388: if ((testFlags & RUN_MVEL) != 0
389: && ((exFlags & RUN_MVEL) != 0)) {
390: try {
391: for (int i = 0; i < count; i++) {
392: MVEL.eval(expression, baseClass);
393: }
394:
395: // System.gc();
396:
397: time = currentTimeMillis();
398: mem = Runtime.getRuntime().freeMemory();
399: for (int reps = 0; reps < TESTITER; reps++) {
400: for (int i = 0; i < count; i++) {
401: MVEL.eval(expression, baseClass);
402: }
403:
404: if (reps == 0)
405: res[0] = total += currentTimeMillis()
406: - time;
407: else
408: res[reps] = (total * -1)
409: + (total += currentTimeMillis()
410: - time - total);
411: }
412:
413: if (!silent)
414: System.out
415: .println("(MVEL) : "
416: + new BigDecimal(
417: ((currentTimeMillis() - time)))
418: .divide(
419: new BigDecimal(
420: TESTITER),
421: 2,
422: RoundingMode.HALF_UP)
423: + "ms avg. (mem delta: "
424: + ((Runtime.getRuntime()
425: .freeMemory() - mem) / 1024)
426: + "kb) " + resultsToString(res));
427:
428: } catch (Exception e) {
429: e.printStackTrace();
430:
431: if (!silent)
432: System.out
433: .println("(MVEL) : <<COULD NOT EXECUTE>>");
434: }
435: }
436:
437: synchronized (this ) {
438: mvelTotal += total;
439: }
440:
441: //
442: // total = 0;
443: //
444: // if ((testFlags & RUN_GROOVY) != 0 && ((exFlags & RUN_GROOVY) != 0)) {
445: // try {
446: // for (int i = 0; i < count; i++) {
447: // Binding binding = new Binding();
448: // for (String var : variables.keySet()) {
449: // binding.setProperty(var, variables.get(var));
450: // }
451: //
452: // GroovyShell groovyShell = new GroovyShell(binding);
453: // groovyShell.evaluate(expression);
454: // }
455: //
456: //
457: // time = currentTimeMillis();
458: // mem = Runtime.getRuntime().freeMemory();
459: // for (int reps = 0; reps < TESTITER; reps++) {
460: // for (int i = 0; i < count; i++) {
461: // Binding binding = new Binding();
462: // for (String var : variables.keySet()) {
463: // binding.setProperty(var, variables.get(var));
464: // }
465: //
466: // GroovyShell groovyShell = new GroovyShell(binding);
467: // groovyShell.evaluate(expression);
468: // }
469: //
470: // if (reps == 0) res[0] = total += currentTimeMillis() - time;
471: // else res[reps] = (total * -1) + (total += currentTimeMillis() - time - total);
472: // }
473: //
474: // if (!silent)
475: // System.out.println("(Groovy) : " + new BigDecimal(((currentTimeMillis() - time))).divide(new BigDecimal(TESTITER), 2, RoundingMode.HALF_UP)
476: // + "ms avg. (mem delta: " + ((Runtime.getRuntime().freeMemory() - mem) / 1024) + "kb) " + resultsToString(res));
477: //
478: // }
479: // catch (Exception e) {
480: // e.printStackTrace();
481: //
482: // if (!silent)
483: // System.out.println("(Groovy) : <<COULD NOT EXECUTE>>");
484: // }
485: // }
486: //
487: // synchronized (this) {
488: // groovyTotal += total;
489: // }
490: //
491: total = 0;
492:
493: if ((testFlags & RUN_COMMONS_EL) != 0
494: && ((exFlags & RUN_COMMONS_EL) != 0)) {
495: VariableResolver vars = new JSPMapVariableResolver(
496: variables);
497:
498: String commonsEx = "${" + expression + "}";
499:
500: try {
501: for (int i = 0; i < count; i++) {
502: new ExpressionEvaluatorImpl(true)
503: .parseExpression(commonsEx,
504: Object.class, null).evaluate(
505: vars);
506: }
507:
508: // System.gc();
509:
510: time = currentTimeMillis();
511: mem = Runtime.getRuntime().freeMemory();
512: for (int reps = 0; reps < TESTITER; reps++) {
513: for (int i = 0; i < count; i++) {
514: new ExpressionEvaluatorImpl(true)
515: .parseExpression(commonsEx,
516: Object.class, null)
517: .evaluate(vars);
518: }
519:
520: if (reps == 0)
521: res[0] = total += currentTimeMillis()
522: - time;
523: else
524: res[reps] = (total * -1)
525: + (total += currentTimeMillis()
526: - time - total);
527: }
528:
529: if (!silent)
530: System.out
531: .println("(CommonsEL) : "
532: + new BigDecimal(
533: ((currentTimeMillis() - time)))
534: .divide(
535: new BigDecimal(
536: TESTITER),
537: 2,
538: RoundingMode.HALF_UP)
539: + "ms avg. (mem delta: "
540: + ((Runtime.getRuntime()
541: .freeMemory() - mem) / 1024)
542: + "kb) " + resultsToString(res));
543:
544: } catch (Exception e) {
545: if (!silent)
546: System.out
547: .println("(CommonsEL) : <<COULD NOT EXECUTE>>");
548: }
549: }
550:
551: synchronized (this ) {
552: commonElTotal += total;
553: }
554:
555: }
556:
557: if ((testFlags & COMPILED) != 0) {
558: runTestCompiled(name, test.getOgnlCompiled(), test
559: .getMvelCompiled(), test.getGroovyCompiled(), test
560: .getElCompiled(), count, exFlags);
561: }
562:
563: total = 0;
564:
565: if ((testFlags & RUN_JAVA_NATIVE) != 0
566: && ((exFlags & RUN_JAVA_NATIVE) != 0)) {
567: NativeTest nt = test.getJavaNative();
568:
569: try {
570: for (int i = 0; i < count; i++) {
571: nt.run(baseClass, variables);
572: }
573:
574: // System.gc();
575:
576: time = currentTimeMillis();
577: mem = Runtime.getRuntime().freeMemory();
578: for (int reps = 0; reps < TESTITER; reps++) {
579: for (int i = 0; i < count; i++) {
580: nt.run(baseClass, variables);
581: }
582:
583: if (reps == 0)
584: res[0] = total += currentTimeMillis() - time;
585: else
586: res[reps] = (total * -1)
587: + (total += currentTimeMillis() - time
588: - total);
589: }
590:
591: if (!silent)
592: System.out
593: .println("(JavaNative) : "
594: + new BigDecimal(
595: ((currentTimeMillis() - time)))
596: .divide(
597: new BigDecimal(
598: TESTITER),
599: 2,
600: RoundingMode.HALF_UP)
601: + "ms avg. (mem delta: "
602: + ((Runtime.getRuntime()
603: .freeMemory() - mem) / 1024)
604: + "kb) " + resultsToString(res));
605:
606: } catch (Exception e) {
607: if (!silent)
608: System.out
609: .println("(JavaNative) : <<COULD NOT EXECUTE>>");
610: }
611: }
612:
613: synchronized (this ) {
614: javaNativeTotal += total;
615: }
616:
617: if (!silent)
618: System.out
619: .println("------------------------------------------------");
620: }
621:
622: public void runTestCompiled(String name, Object compiledOgnl,
623: Object compiledMvel, Object compiledGroovy,
624: Expression compiledEl, int count, int exFlags)
625: throws Exception {
626:
627: long time;
628: long mem;
629: long total = 0;
630: long[] res = new long[TESTITER];
631:
632: if (!silent)
633: System.out.println("Compiled Results :");
634:
635: if ((testFlags & RUN_OGNL) != 0 && ((exFlags & RUN_OGNL) != 0)) {
636: try {
637: for (int i = 0; i < count; i++) {
638: Ognl.getValue(compiledOgnl, baseClass);
639: }
640:
641: time = currentTimeMillis();
642: mem = Runtime.getRuntime().freeMemory();
643:
644: for (int reps = 0; reps < TESTITER; reps++) {
645: for (int i = 0; i < count; i++) {
646: Ognl.getValue(compiledOgnl, baseClass);
647: }
648:
649: if (reps == 0)
650: res[0] = total += currentTimeMillis() - time;
651: else
652: res[reps] = (total * -1)
653: + (total += currentTimeMillis() - time
654: - total);
655: }
656:
657: if (!silent)
658: System.out
659: .println("(OGNL Compiled) : "
660: + new BigDecimal(
661: currentTimeMillis() - time)
662: .divide(
663: new BigDecimal(
664: TESTITER),
665: 2,
666: RoundingMode.HALF_UP)
667: + "ms avg. (mem delta: "
668: + ((Runtime.getRuntime()
669: .freeMemory() - mem) / 1024)
670: + "kb) " + resultsToString(res));
671: } catch (Exception e) {
672:
673: if (!silent)
674: System.out
675: .println("(OGNL) : <<COULD NOT EXECUTE>>");
676: }
677: }
678:
679: synchronized (this ) {
680: ognlTotal += total;
681: }
682:
683: total = 0;
684:
685: if ((testFlags & RUN_MVEL) != 0 && ((exFlags & RUN_MVEL)) != 0) {
686:
687: try {
688: for (int i = 0; i < count; i++) {
689: MVEL.executeExpression(compiledMvel, baseClass);
690: }
691:
692: time = currentTimeMillis();
693: mem = Runtime.getRuntime().freeMemory();
694:
695: for (int reps = 0; reps < TESTITER; reps++) {
696: for (int i = 0; i < count; i++) {
697: MVEL.executeExpression(compiledMvel, baseClass);
698: }
699:
700: if (reps == 0)
701: res[0] = total += currentTimeMillis() - time;
702: else
703: res[reps] = (total * -1)
704: + (total += currentTimeMillis() - time
705: - total);
706: }
707:
708: if (!silent)
709: System.out
710: .println("(MVEL Compiled) : "
711: + new BigDecimal(
712: currentTimeMillis() - time)
713: .divide(
714: new BigDecimal(
715: TESTITER),
716: 2,
717: RoundingMode.HALF_UP)
718: + "ms avg. (mem delta: "
719: + ((Runtime.getRuntime()
720: .freeMemory() - mem) / 1024)
721: + "kb) " + resultsToString(res));
722: } catch (Exception e) {
723:
724: if (!silent)
725: System.out
726: .println("(MVEL) : <<COULD NOT EXECUTE>>");
727: }
728:
729: synchronized (this ) {
730: mvelTotal += total;
731: }
732:
733: total = 0;
734: }
735:
736: // total = 0;
737: //
738: // if ((testFlags & RUN_GROOVY) != 0 && ((exFlags & RUN_GROOVY)) != 0) {
739: //
740: // try {
741: // for (int i = 0; i < count; i++) {
742: // Binding binding = new Binding();
743: // for (String var : variables.keySet()) {
744: // binding.setProperty(var, variables.get(var));
745: // }
746: //
747: // Script script = (Script) compiledGroovy;
748: // script.setBinding(binding);
749: // script.run();
750: // }
751: //
752: // time = currentTimeMillis();
753: // mem = Runtime.getRuntime().freeMemory();
754: //
755: // for (int reps = 0; reps < TESTITER; reps++) {
756: // for (int i = 0; i < count; i++) {
757: // Binding binding = new Binding();
758: // for (String var : variables.keySet()) {
759: // binding.setProperty(var, variables.get(var));
760: // }
761: //
762: // Script script = (Script) compiledGroovy;
763: // script.setBinding(binding);
764: // script.run();
765: // }
766: //
767: // if (reps == 0) res[0] = total += currentTimeMillis() - time;
768: // else res[reps] = (total * -1) + (total += currentTimeMillis() - time - total);
769: // }
770: //
771: // if (!silent)
772: // System.out.println("(Groovy Compiled) : " + new BigDecimal(currentTimeMillis() - time).divide(new BigDecimal(TESTITER), 2, RoundingMode.HALF_UP)
773: // + "ms avg. (mem delta: " + ((Runtime.getRuntime().freeMemory() - mem) / 1024) + "kb) " + resultsToString(res));
774: // }
775: // catch (Exception e) {
776: //
777: // if (!silent)
778: // System.out.println("(Groovy) : <<COULD NOT EXECUTE>>");
779: // }
780: //
781: //
782: // synchronized (this) {
783: // groovyTotal += total;
784: // }
785: //
786: // total = 0;
787: // }
788: //
789:
790: if ((testFlags & RUN_COMMONS_EL) != 0
791: && ((exFlags & RUN_COMMONS_EL) != 0)) {
792: VariableResolver vars = new JSPMapVariableResolver(
793: variables);
794: try {
795: for (int i = 0; i < count; i++) {
796: compiledEl.evaluate(vars);
797: }
798:
799: time = currentTimeMillis();
800: mem = Runtime.getRuntime().freeMemory();
801: for (int reps = 0; reps < TESTITER; reps++) {
802: for (int i = 0; i < count; i++) {
803: compiledEl.evaluate(vars);
804: }
805:
806: if (reps == 0)
807: res[0] = total += currentTimeMillis() - time;
808: else
809: res[reps] = (total * -1)
810: + (total += currentTimeMillis() - time
811: - total);
812: }
813:
814: if (!silent)
815: System.out
816: .println("(CommonsEL Compiled) : "
817: + new BigDecimal(
818: ((currentTimeMillis() - time)))
819: .divide(
820: new BigDecimal(
821: TESTITER),
822: 2,
823: RoundingMode.HALF_UP)
824: + "ms avg. (mem delta: "
825: + ((Runtime.getRuntime()
826: .freeMemory() - mem) / 1024)
827: + "kb) " + resultsToString(res));
828:
829: } catch (Exception e) {
830: if (!silent)
831: System.out
832: .println("(CommonsEL Compiled) : <<COULD NOT EXECUTE>>");
833: }
834: }
835:
836: synchronized (this ) {
837: commonElTotal += total;
838: }
839:
840: }
841:
842: private static String resultsToString(long[] res) {
843: StringBuffer sbuf = new StringBuffer("[");
844: for (int i = 0; i < res.length; i++) {
845: sbuf.append(res[i]);
846:
847: if ((i + 1) < res.length)
848: sbuf.append(",");
849: }
850: sbuf.append("]");
851:
852: return sbuf.toString();
853: }
854:
855: public long getOgnlTotal() {
856: return ognlTotal;
857: }
858:
859: public void setOgnlTotal(long ognlTotal) {
860: this .ognlTotal = ognlTotal;
861: }
862:
863: public long getMvelTotal() {
864: return mvelTotal;
865: }
866:
867: public void setMvelTotal(long mvelTotal) {
868: this .mvelTotal = mvelTotal;
869: }
870:
871: public long getCommonElTotal() {
872: return commonElTotal;
873: }
874:
875: public void setCommonElTotal(long commonElTotal) {
876: this .commonElTotal = commonElTotal;
877: }
878:
879: public long getJavaNativeTotal() {
880: return javaNativeTotal;
881: }
882:
883: public void setJavaNativeTotal(long javaNativeTotal) {
884: this .javaNativeTotal = javaNativeTotal;
885: }
886:
887: public long getGroovyTotal() {
888: return groovyTotal;
889: }
890:
891: public void setGroovyTotal(long groovyTotal) {
892: this .groovyTotal = groovyTotal;
893: }
894:
895: public boolean isSilent() {
896: return silent;
897: }
898:
899: public void setSilent(boolean silent) {
900: this .silent = silent;
901: }
902:
903: public void reset() {
904: ognlTotal = 0;
905: mvelTotal = 0;
906: javaNativeTotal = 0;
907: commonElTotal = 0;
908: }
909: }
|