You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2015/01/21 14:31:30 UTC

svn commit: r1653535 - /tomcat/trunk/test/org/apache/el/parser/TestELParser.java

Author: markt
Date: Wed Jan 21 13:31:30 2015
New Revision: 1653535

URL: http://svn.apache.org/r1653535
Log:
Add a test case I have been using to explore possible performance gains in the EL parser. This is in preparation for the fix for BZ 57441.

Modified:
    tomcat/trunk/test/org/apache/el/parser/TestELParser.java

Modified: tomcat/trunk/test/org/apache/el/parser/TestELParser.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/el/parser/TestELParser.java?rev=1653535&r1=1653534&r2=1653535&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/el/parser/TestELParser.java (original)
+++ tomcat/trunk/test/org/apache/el/parser/TestELParser.java Wed Jan 21 13:31:30 2015
@@ -17,6 +17,8 @@
 
 package org.apache.el.parser;
 
+import java.io.StringReader;
+
 import javax.el.ELContext;
 import javax.el.ELException;
 import javax.el.ExpressionFactory;
@@ -25,9 +27,11 @@ import javax.el.ValueExpression;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import org.junit.Ignore;
 import org.junit.Test;
 
 import org.apache.jasper.el.ELContextImpl;
+import org.apache.tomcat.util.collections.SynchronizedStack;
 
 public class TestELParser {
 
@@ -229,4 +233,61 @@ public class TestELParser {
         String result = (String) ve.getValue(context);
         assertEquals(expected, result);
     }
+
+    /*
+     * Test to explore if re-using Parser instances is faster.
+     *
+     * Tests on my laptop show:
+     * - overhead by introducing the stack is in the noise for parsing even the
+     *   simplest expression
+     * - efficiency from re-using the ELParser is measurable for even a single
+     *   reuse of the parser
+     * - with large numbers of parses (~10k) performance for a trivial parse is
+     *   three times faster
+     * - around the 100 iterations mark GC overhead adds significant noise to
+     *   the results - for consistent results you either need fewer parses to
+     *   avoid triggering GC or more parses so the GC effects are evenly
+     *   distributed between the runs
+     *
+     * Note that the test is single threaded.
+     */
+    @Ignore
+    @Test
+    public void testParserPerformance() throws ParseException {
+        final int runs = 20;
+        final int parseIterations = 10000;
+
+
+        for (int j = 0; j < runs; j ++) {
+            long start = System.nanoTime();
+            SynchronizedStack<ELParser> stack = new SynchronizedStack<>();
+
+            for (int i = 0; i < parseIterations; i ++) {
+                ELParser parser = stack.pop();
+                if (parser == null) {
+                    parser = new ELParser(new StringReader("${'foo'}"));
+                } else {
+                    parser.ReInit(new StringReader("${'foo'}"));
+                }
+                parser.CompositeExpression();
+                stack.push(parser);
+            }
+            long end = System.nanoTime();
+
+            System.out.println(parseIterations +
+                    " iterations using ELParser.ReInit(...) took " + (end - start) + "ns");
+        }
+
+        for (int j = 0; j < runs; j ++) {
+            long start = System.nanoTime();
+            for (int i = 0; i < parseIterations; i ++) {
+                ELParser parser = new ELParser(new StringReader("${'foo'}"));
+                parser.CompositeExpression();
+            }
+            long end = System.nanoTime();
+
+            System.out.println(parseIterations +
+                    " iterations using    new ELParser(...) took " + (end - start) + "ns");
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org