This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 32a57904e46ce3f02efc532c4293e3487f3c5f7c Author: Mark Thomas <[email protected]> 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 +++++++ .../juli/TestOneLineFormatterPerformance.java | 31 +++++++++++++++------- .../util/buf/TestCharsetCachePerformance.java | 30 ++++++++++----------- 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/test/org/apache/el/parser/TestELParserPerformance.java b/test/org/apache/el/parser/TestELParserPerformance.java index de2aa9d1e0..eb860f4be9 100644 --- a/test/org/apache/el/parser/TestELParserPerformance.java +++ b/test/org/apache/el/parser/TestELParserPerformance.java @@ -20,10 +20,14 @@ import java.io.StringReader; import jakarta.el.ELBaseTest; +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 extends ELBaseTest { /* @@ -48,6 +52,8 @@ public class TestELParserPerformance extends ELBaseTest { 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(); @@ -64,6 +70,7 @@ public class TestELParserPerformance extends ELBaseTest { stack.push(parser); } long end = System.nanoTime(); + reinitTotalTime += (end - start); System.out.println(parseIterations + " iterations using ELParser.ReInit(...) took " + (end - start) + "ns"); @@ -76,9 +83,12 @@ public class TestELParserPerformance extends ELBaseTest { 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/juli/TestOneLineFormatterPerformance.java b/test/org/apache/juli/TestOneLineFormatterPerformance.java index 54b1e33ebd..a90ebd6529 100644 --- a/test/org/apache/juli/TestOneLineFormatterPerformance.java +++ b/test/org/apache/juli/TestOneLineFormatterPerformance.java @@ -16,6 +16,7 @@ */ package org.apache.juli; +import org.junit.Assert; import org.junit.Test; /** @@ -28,19 +29,29 @@ public class TestOneLineFormatterPerformance { @Test public void testDateFormat() throws Exception { + DateFormat stringFormatImpl = new StringFormatImpl(); + long stringFormatImplTime = doTestDateFormat(stringFormatImpl); + + DateFormat dateFormatCacheImpl = new DateFormatCacheImpl(); + long dateFormatCacheImplTime = doTestDateFormat(dateFormatCacheImpl); + + Assert.assertTrue("String#format was faster that DateFormatCache", + dateFormatCacheImplTime < stringFormatImplTime); + } + + + private long doTestDateFormat(DateFormat df) { int iters = 1000000; - DateFormat[] dfs = new DateFormat[] { new StringFormatImpl(), new DateFormatCacheImpl() }; - - for (DateFormat df : dfs) { - long start = System.nanoTime(); - for (int i = 0; i < iters; i++) { - df.format(System.nanoTime()); - } - long end = System.nanoTime(); - System.out.println( - "Impl: [" + df.getClass().getName() + "] took [" + (end-start) + "] ns"); + + long start = System.nanoTime(); + for (int i = 0; i < iters; i++) { + df.format(System.nanoTime()); } + long end = System.nanoTime(); + System.out.println( + "Impl: [" + df.getClass().getName() + "] took [" + (end - start) + "] ns"); + return end - start; } 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: [email protected] For additional commands, e-mail: [email protected]
