ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/http/TesterParametersPerformance.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/http/TesterParametersPerformance.java
Status
scanned
Type
file
Name
TesterParametersPerformance.java
Extension
.java
Programming language
Java
Mime type
text/x-Algol68
File type
Algol 68 source, ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
5457 (5.3 KB)
MD5
baa614a3721eb16f8707b5b4277f3dcf
SHA1
b47de3fcb147e07d61a1859ffd079aea470db94c
SHA256
022789b3485035fdf89ff1926343298bcd13d46621b601a0a4fa5588359dbee8
SHA512

      
    
SHA1_git
37bf88009175927b4f7bad9110fbe2131fa8f260
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TesterParametersPerformance.java | 5.3 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.tomcat.util.http; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.logging.Level; import java.util.logging.LogManager; import org.junit.Assert; import org.junit.Test; import org.apache.tomcat.util.buf.B2CConverter; /* * This is an absolute performance test. There is no benefit it running it as part of a standard test run so it is * excluded due to the name starting Tester... */ public class TesterParametersPerformance { @Test public void testProcessParametersByteArrayIntInt() { LogManager.getLogManager().getLogger("").setLevel(Level.OFF); doTestProcessParametersMultiple("foo".getBytes()); } private void doTestProcessParametersMultiple(byte[] input) { System.out.println(doTestProcessParameters(input, 10000)); System.out.println(doTestProcessParameters(input, 20000)); System.out.println(doTestProcessParameters(input, 40000)); System.out.println(doTestProcessParameters(input, 80000)); System.out.println(doTestProcessParameters(input, 160000)); System.out.println(doTestProcessParameters(input, 320000)); System.out.println(doTestProcessParameters(input, 640000)); System.out.println(doTestProcessParameters(input, 1280000)); } private long doTestProcessParameters(byte[] input, int size) { Assert.assertEquals(input.length, 3); Parameters p = new Parameters(); byte[] params = createParams(input, size); //byte[] input = createParams(8); p.setCharset(StandardCharsets.ISO_8859_1); long start = System.nanoTime(); p.processParameters(params, 0, params.length); return System.nanoTime() - start; } private byte[] createParams(byte[] input, int len) { byte[] result = new byte[len * 4 - 1]; for (int i = 0; i < len; i++) { result[i * 4] = input[0]; result[i * 4 + 1] = input[1]; result[i * 4 + 2] = input[2]; if (i < len -1) { result[i * 4 + 3] = 38; } } return result; } @Test public void testCreateString() throws UnsupportedEncodingException { B2CConverter.getCharset("ISO-8859-1"); doCreateStringMultiple("foo"); } private void doCreateStringMultiple(String input) { System.out.println(doCreateString(input, 10, true)); System.out.println(doCreateString(input, 100, true)); System.out.println(doCreateString(input, 1000, true)); System.out.println(doCreateString(input, 10000, true)); System.out.println(doCreateString(input, 100000, true)); System.out.println(doCreateString(input, 1000000, true)); System.out.println(doCreateString(input, 2000000, true)); //System.out.println(doCreateString(input, 4000000, true)); //System.out.println(doCreateString(input, 8000000, true)); System.out.println(doCreateString(input, 10, false)); System.out.println(doCreateString(input, 100, false)); System.out.println(doCreateString(input, 1000, false)); System.out.println(doCreateString(input, 10000, false)); System.out.println(doCreateString(input, 100000, false)); System.out.println(doCreateString(input, 1000000, false)); System.out.println(doCreateString(input, 2000000, false)); //System.out.println(doCreateString(input, 4000000, false)); //System.out.println(doCreateString(input, 8000000, false)); } private long doCreateString(String input, int size, boolean defensiveCopyWorkAround) { int loops = 10000; byte[] inputBytes = input.getBytes(); byte[] bytes = new byte[size]; int inputLength = inputBytes.length; System.arraycopy(inputBytes, 0, bytes, 0, inputLength); String[] result = new String[loops]; Charset charset = StandardCharsets.ISO_8859_1; long start = System.nanoTime(); for (int i = 0; i < loops; i++) { if (defensiveCopyWorkAround) { byte[] tmp = new byte[inputLength]; System.arraycopy(bytes, 0, tmp, 0, inputLength); result[i] = new String(tmp, 0, inputLength, charset); } else { result[i] = new String(bytes, 0, inputLength, charset); } } return System.nanoTime() - start; } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
20.34
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