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


The following commit(s) were added to refs/heads/main by this push:
     new 05b967e29e Try and make test more reliable when running with other 
tests
05b967e29e is described below

commit 05b967e29e54a69592305e1170554b1d7e731c48
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Sep 3 18:46:28 2024 +0100

    Try and make test more reliable when running with other tests
    
    When run on its own, the optimised code is consistently faster.
---
 .../catalina/util/TestParameterMapPerformance.java    | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/test/org/apache/catalina/util/TestParameterMapPerformance.java 
b/test/org/apache/catalina/util/TestParameterMapPerformance.java
index a9bf7e9f34..fe2ea9bf79 100644
--- a/test/org/apache/catalina/util/TestParameterMapPerformance.java
+++ b/test/org/apache/catalina/util/TestParameterMapPerformance.java
@@ -26,8 +26,9 @@ import org.junit.Test;
 
 public class TestParameterMapPerformance {
 
-    private final int numTests = 5;
-    private final int numTestIterations = 1000000;
+    private static final int NUM_TESTS = 10;
+    private static final int NUM_SKIP = 4;
+    private static final int NUM_TEST_ITERATIONS = 1000000;
 
     private ParameterMap<Integer,Object> baseParams;
     private ParameterMap<Integer,Object> testParams;
@@ -44,16 +45,16 @@ public class TestParameterMapPerformance {
         baseParams.setLocked(true);
 
         // warmup
-        for (int i = 0; i < numTestIterations; i++) {
+        for (int i = 0; i < NUM_TEST_ITERATIONS; i++) {
             useStandardConstructor();
             useOptimizedMapConstructor();
         }
 
         List<Long> standardDurations = new ArrayList<>();
-        for (int i = 0; i < numTests; i++) {
+        for (int i = 0; i < NUM_TESTS; i++) {
             System.gc();
             long startStandard = System.currentTimeMillis();
-            for (int j = 0; j < numTestIterations; j++) {
+            for (int j = 0; j < NUM_TEST_ITERATIONS; j++) {
                 useStandardConstructor();
             }
             long duration = System.currentTimeMillis() - startStandard;
@@ -64,13 +65,13 @@ public class TestParameterMapPerformance {
          * The CI systems tend to produce outliers that lead to false failures 
so skip the longest two runs.
          */
         long standardTotalDuration =
-                standardDurations.stream().sorted().limit(numTests - 
2).reduce(Long::sum).get().longValue();
+                standardDurations.stream().sorted().limit(NUM_TESTS - 
2).reduce(Long::sum).get().longValue();
 
         List<Long> optimizedDurations = new ArrayList<>();
-        for (int i = 0; i < numTests; i++) {
+        for (int i = 0; i < NUM_TESTS; i++) {
             System.gc();
             long startOptimized = System.currentTimeMillis();
-            for (int j = 0; j < numTestIterations; j++) {
+            for (int j = 0; j < NUM_TEST_ITERATIONS; j++) {
                 useOptimizedMapConstructor();
             }
             long duration = System.currentTimeMillis() - startOptimized;
@@ -81,7 +82,7 @@ public class TestParameterMapPerformance {
          * The CI systems tend to produce outliers that lead to false failures 
so skip the longest two runs.
          */
         long optimizedTotalDuration =
-                optimizedDurations.stream().sorted().limit(numTests - 
2).reduce(Long::sum).get().longValue();
+                optimizedDurations.stream().sorted().limit(NUM_TESTS - 
NUM_SKIP).reduce(Long::sum).get().longValue();
 
         Assert.assertTrue("Standard: " + standardTotalDuration + "ms, 
Optimized: " + optimizedTotalDuration + "ms",
                 optimizedTotalDuration < standardTotalDuration);


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

Reply via email to