This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit e854ef7ac1fdb02a708a694dfdf8ca7dafc8744a
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jan 8 12:08:21 2024 +0000

    Refactor so these relative performance tests generate pass/fail results
---
 .../apache/el/parser/TestELParserPerformance.java  | 10 ++++++++
 .../util/buf/TestCharsetCachePerformance.java      | 30 +++++++++++-----------
 2 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/test/org/apache/el/parser/TestELParserPerformance.java 
b/test/org/apache/el/parser/TestELParserPerformance.java
index f4d90e7f9e..6a282cded6 100644
--- a/test/org/apache/el/parser/TestELParserPerformance.java
+++ b/test/org/apache/el/parser/TestELParserPerformance.java
@@ -18,10 +18,14 @@ package org.apache.el.parser;
 
 import java.io.StringReader;
 
+import org.junit.Assert;
 import org.junit.Test;
 
 import org.apache.tomcat.util.collections.SynchronizedStack;
 
+/*
+ * This is a relative performance test so it remains part of the standard test 
run.
+ */
 public class TestELParserPerformance {
 
     /*
@@ -46,6 +50,8 @@ public class TestELParserPerformance {
         final int runs = 20;
         final int parseIterations = 10000;
 
+        long reinitTotalTime = 0;
+        long newTotalTime = 0;
 
         for (int j = 0; j < runs; j ++) {
             long start = System.nanoTime();
@@ -62,6 +68,7 @@ public class TestELParserPerformance {
                 stack.push(parser);
             }
             long end = System.nanoTime();
+            reinitTotalTime +=  (end - start);
 
             System.out.println(parseIterations +
                     " iterations using ELParser.ReInit(...) took " + (end - 
start) + "ns");
@@ -74,9 +81,12 @@ public class TestELParserPerformance {
                 parser.CompositeExpression();
             }
             long end = System.nanoTime();
+            newTotalTime +=  (end - start);
 
             System.out.println(parseIterations +
                     " iterations using    new ELParser(...) took " + (end - 
start) + "ns");
         }
+
+        Assert.assertTrue("Using new ElParser() was faster then using 
ELParser.ReInit", reinitTotalTime < newTotalTime);
     }
 }
diff --git a/test/org/apache/tomcat/util/buf/TestCharsetCachePerformance.java 
b/test/org/apache/tomcat/util/buf/TestCharsetCachePerformance.java
index 2ad8f7f142..f17098488e 100644
--- a/test/org/apache/tomcat/util/buf/TestCharsetCachePerformance.java
+++ b/test/org/apache/tomcat/util/buf/TestCharsetCachePerformance.java
@@ -21,29 +21,27 @@ import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 
+import org.junit.Assert;
 import org.junit.Test;
 
+/*
+ * This is a relative performance test so it remains part of the standard test 
run.
+ */
 public class TestCharsetCachePerformance {
 
     @Test
-    public void testNoCsCache() throws Exception {
-        doTest(new NoCsCache());
-    }
-
-
-    @Test
-    public void testFullCsCache() throws Exception {
-        doTest(new FullCsCache());
+    public void testCache() throws Exception {
+        long timeNone = doTest(new NoCsCache());
+        long timeFull = doTest(new FullCsCache());
+        long timeLazy = doTest(new LazyCsCache());
+
+        Assert.assertTrue("No cache was faster than full cache", timeFull < 
timeNone);
+        Assert.assertTrue("No cache was faster than lazy cache", timeLazy < 
timeNone);
+        Assert.assertTrue("Lazy cache was faster than full cache ", timeFull < 
timeLazy);
     }
 
 
-    @Test
-    public void testLazyCsCache() throws Exception {
-        doTest(new LazyCsCache());
-    }
-
-
-    private void doTest(CsCache cache) throws Exception {
+    private long doTest(CsCache cache) throws Exception {
         int threadCount = 10;
         int iterations = 10000000;
         String[] lookupNames = new String[] {
@@ -68,6 +66,8 @@ public class TestCharsetCachePerformance {
         long endTime = System.nanoTime();
 
         System.out.println(cache.getClass().getName() + ": " + (endTime - 
startTime) + "ns");
+
+        return endTime - startTime;
     }
 
 


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

Reply via email to