You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2012/03/15 11:45:19 UTC
svn commit: r1300900 -
/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TesterParametersPerformance.java
Author: markt
Date: Thu Mar 15 10:45:19 2012
New Revision: 1300900
URL: http://svn.apache.org/viewvc?rev=1300900&view=rev
Log:
Add test code present in trunk but not 7.0.x
Added:
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TesterParametersPerformance.java (contents, props changed)
- copied, changed from r1190387, tomcat/trunk/test/org/apache/tomcat/util/http/TesterParametersPerformance.java
Copied: tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TesterParametersPerformance.java (from r1190387, tomcat/trunk/test/org/apache/tomcat/util/http/TesterParametersPerformance.java)
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TesterParametersPerformance.java?p2=tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TesterParametersPerformance.java&p1=tomcat/trunk/test/org/apache/tomcat/util/http/TesterParametersPerformance.java&r1=1190387&r2=1300900&rev=1300900&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/http/TesterParametersPerformance.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TesterParametersPerformance.java Thu Mar 15 10:45:19 2012
@@ -1,133 +1,133 @@
-/*
- * 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.util.logging.Level;
-import java.util.logging.LogManager;
-
-import static org.junit.Assert.assertEquals;
-import org.junit.Test;
-
-import org.apache.tomcat.util.buf.B2CConverter;
-
-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) {
- assertEquals(input.length, 3);
-
- Parameters p = new Parameters();
-
- byte[] params = createParams(input, size);
- //byte[] input = createParams(8);
- p.setEncoding("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 = null;
- try {
- charset = B2CConverter.getCharset("ISO-8859-1");
- } catch (UnsupportedEncodingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- 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;
- }
-}
+/*
+ * 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.util.logging.Level;
+import java.util.logging.LogManager;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+import org.apache.tomcat.util.buf.B2CConverter;
+
+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) {
+ assertEquals(input.length, 3);
+
+ Parameters p = new Parameters();
+
+ byte[] params = createParams(input, size);
+ //byte[] input = createParams(8);
+ p.setEncoding("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 = null;
+ try {
+ charset = B2CConverter.getCharset("ISO-8859-1");
+ } catch (UnsupportedEncodingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ 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;
+ }
+}
Propchange: tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TesterParametersPerformance.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org