From: markt Date: Mon, 10 Oct 2011 11:56:02 +0000 (+0000) Subject: Add a performance test that demonstrates why using URI is currently poor for performance X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f9fc9f7e613022895fe409afb07c6386f55d5ad1;p=tomcat7.0 Add a performance test that demonstrates why using URI is currently poor for performance git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1180891 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/test/org/apache/catalina/connector/TestResponsePerformance.java b/test/org/apache/catalina/connector/TestResponsePerformance.java new file mode 100644 index 000000000..69ff9fc8e --- /dev/null +++ b/test/org/apache/catalina/connector/TestResponsePerformance.java @@ -0,0 +1,72 @@ +/* + * 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 static org.junit.Assert.assertTrue; +import org.junit.Test; + +public class TestResponsePerformance { + @Test + public void testToAbsolutePerformance() throws Exception { + Request req = new TesterToAbsoluteRequest(); + Response resp = new Response(); + resp.setRequest(req); + + long start = System.currentTimeMillis(); + for (int i = 0; i < 100000; i++) { + resp.toAbsolute("bar.html"); + } + long homebrew = System.currentTimeMillis() - start; + + start = System.currentTimeMillis(); + for (int i = 0; i < 100000; i++) { + URI base = URI.create("http://localhost:8080/foo.html"); + base.resolve(URI.create("bar.html")).toASCIIString(); + } + long uri = System.currentTimeMillis() - start; + + System.out.println("Current 'home-brew': " + homebrew + + "ms, Using URI: " + uri + "ms"); + assertTrue(homebrew < uri); + } + + + private static class TesterToAbsoluteRequest extends Request { + + @Override + public String getScheme() { + return "http"; + } + + @Override + public String getServerName() { + return "localhost"; + } + + @Override + public int getServerPort() { + return 8080; + } + + @Override + public String getDecodedRequestURI() { + return "/foo.html"; + } + } +}