ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/connector/TestResponsePerformance.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/connector/TestResponsePerformance.java
Status
scanned
Type
file
Name
TestResponsePerformance.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
3168 (3.1 KB)
MD5
7b78e3d9d2d7e22d82e252a3987f59b5
SHA1
04f89756755ac27125719081e25723ac3a4b45c3
SHA256
d32aa97f72249ed81f5846fa08c3246aed264fa131be860298c013c14b19fa5e
SHA512

      
    
SHA1_git
095131643ad26a1b74954205a41f7ac472466f71
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestResponsePerformance.java | 3.1 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.catalina.connector; import java.net.URI; import org.junit.Assert; import org.junit.Test; import org.apache.catalina.startup.LoggingBaseTest; import org.apache.tomcat.unittest.TesterRequest; /* * This is a relative performance test so it remains part of the standard test run. If the test fails then we need to * looking at why and possibly disable/remove the homebrew approach for some OS/Java combinations. */ public class TestResponsePerformance extends LoggingBaseTest { private static final int ITERATIONS = 1000000; @Test public void testToAbsolutePerformance() throws Exception { Request req = new TesterRequest(); Response resp = new Response(null); resp.setRequest(req); // Warm up doHomebrew(resp); doUri(); // Note: With Java 11 the 'homebrew' approach is consistently 3-4 times faster on both MacOS (Intel) and Linux // With Java 22 EA the 'homebrew' approach is consistently a little over 2x faster on MacOS (M1) // To allow for timing differences between runs, a "best of n" approach // is taken for this test final int bestOf = 5; final int winTarget = (bestOf + 1) / 2; int homebrewWin = 0; int count = 0; while (count < bestOf && homebrewWin < winTarget) { long homebrew = doHomebrew(resp); long uri = doUri(); log.info("Current 'home-brew': " + homebrew + "ms, Using URI: " + uri + "ms"); if (homebrew < uri) { homebrewWin++; } count++; } Assert.assertTrue(homebrewWin == winTarget); } private long doHomebrew(Response resp) { long start = System.currentTimeMillis(); for (int i = 0; i < ITERATIONS; i++) { resp.toAbsolute("bar.html"); } return System.currentTimeMillis() - start; } private long doUri() { long start = System.currentTimeMillis(); for (int i = 0; i < ITERATIONS; i++) { URI base = URI.create("http://localhost:8080/level1/level2/foo.html"); base.resolve(URI.create("bar.html")).toASCIIString(); } return System.currentTimeMillis() - start; } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
31.56
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9