This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit aebc402308129424590f32fa8b9f3285451d3033 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 +++++++ .../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 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/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: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org