You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by mw...@apache.org on 2008/12/29 20:25:35 UTC
svn commit: r729978 - in
/james/mime4j/trunk/benchmarks/src/org/apache/james/mime4j:
Base64InputStreamBench.java Base64OutputStreamBench.java
Author: mwiederkehr
Date: Mon Dec 29 11:25:35 2008
New Revision: 729978
URL: http://svn.apache.org/viewvc?rev=729978&view=rev
Log:
added base64 I/O stream benchmarks from MIME4J-71 and MIME4J-92.
Added:
james/mime4j/trunk/benchmarks/src/org/apache/james/mime4j/Base64InputStreamBench.java
james/mime4j/trunk/benchmarks/src/org/apache/james/mime4j/Base64OutputStreamBench.java
Added: james/mime4j/trunk/benchmarks/src/org/apache/james/mime4j/Base64InputStreamBench.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/benchmarks/src/org/apache/james/mime4j/Base64InputStreamBench.java?rev=729978&view=auto
==============================================================================
--- james/mime4j/trunk/benchmarks/src/org/apache/james/mime4j/Base64InputStreamBench.java (added)
+++ james/mime4j/trunk/benchmarks/src/org/apache/james/mime4j/Base64InputStreamBench.java Mon Dec 29 11:25:35 2008
@@ -0,0 +1,109 @@
+/****************************************************************
+ * 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.james.mime4j;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Random;
+
+import org.apache.commons.io.output.NullOutputStream;
+import org.apache.james.mime4j.decoder.Base64InputStream;
+import org.apache.james.mime4j.decoder.CodecUtil;
+
+public class Base64InputStreamBench {
+
+ public static void main(String[] args) throws Exception {
+ byte[] data = initData(2 * 1024 * 1024);
+ byte[] encoded = encode(data);
+
+ // decoder test to make sure everything is okay
+
+ testDecode(data, encoded);
+
+ // warmup
+
+ OutputStream nullOut = new NullOutputStream();
+
+ for (int i = 0; i < 5; i++) {
+ ByteArrayInputStream ed = new ByteArrayInputStream(encoded);
+ InputStream in = new Base64InputStream(ed);
+ CodecUtil.copy(in, nullOut);
+ }
+ Thread.sleep(100);
+
+ // test
+
+ long t0 = System.currentTimeMillis();
+
+ final int repetitions = 50;
+ for (int i = 0; i < repetitions; i++) {
+ ByteArrayInputStream ed = new ByteArrayInputStream(encoded);
+ InputStream in = new Base64InputStream(ed);
+ CodecUtil.copy(in, nullOut);
+ }
+
+ long dt = System.currentTimeMillis() - t0;
+ long totalBytes = data.length * (long) repetitions;
+
+ double mbPerSec = (totalBytes / 1024.0 / 1024) / (dt / 1000.0);
+
+ System.out.println(dt + " ms");
+ System.out.println(totalBytes + " bytes");
+ System.out.println(mbPerSec + " mb/sec");
+ }
+
+ private static byte[] initData(int size) {
+ Random random = new Random(size);
+ byte[] data = new byte[size];
+ random.nextBytes(data);
+ return data;
+ }
+
+ private static byte[] encode(byte[] data) throws IOException {
+ InputStream in = new ByteArrayInputStream(data);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ CodecUtil.encodeBase64(in, out);
+ return out.toByteArray();
+ }
+
+ private static void testDecode(byte[] data, final byte[] encoded)
+ throws IOException {
+ ByteArrayInputStream ed = new ByteArrayInputStream(encoded);
+ InputStream in = new Base64InputStream(ed);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ CodecUtil.copy(in, out);
+
+ compare(data, out.toByteArray());
+ }
+
+ private static void compare(byte[] expected, byte[] actual) {
+ if (expected.length != actual.length)
+ throw new AssertionError("length: " + expected.length + ", "
+ + actual.length);
+
+ for (int i = 0; i < expected.length; i++)
+ if (expected[i] != actual[i])
+ throw new AssertionError("value @ " + i);
+ }
+
+}
\ No newline at end of file
Added: james/mime4j/trunk/benchmarks/src/org/apache/james/mime4j/Base64OutputStreamBench.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/benchmarks/src/org/apache/james/mime4j/Base64OutputStreamBench.java?rev=729978&view=auto
==============================================================================
--- james/mime4j/trunk/benchmarks/src/org/apache/james/mime4j/Base64OutputStreamBench.java (added)
+++ james/mime4j/trunk/benchmarks/src/org/apache/james/mime4j/Base64OutputStreamBench.java Mon Dec 29 11:25:35 2008
@@ -0,0 +1,70 @@
+/****************************************************************
+ * 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.james.mime4j;
+
+import java.io.OutputStream;
+import java.util.Random;
+
+import org.apache.commons.io.output.NullOutputStream;
+import org.apache.james.mime4j.decoder.Base64OutputStream;
+
+public class Base64OutputStreamBench {
+
+ public static void main(String[] args) throws Exception {
+ byte[] data = initData(1024);
+
+ OutputStream nullOut = new NullOutputStream();
+ Base64OutputStream base64Out = new Base64OutputStream(nullOut);
+
+ // warmup
+
+ for (int i = 0; i < 2000; i++) {
+ base64Out.write(data);
+ }
+ Thread.sleep(100);
+
+ // test
+
+ long t0 = System.currentTimeMillis();
+
+ final int repetitions = 500000;
+ for (int i = 0; i < repetitions; i++) {
+ base64Out.write(data);
+ }
+ base64Out.close();
+
+ long dt = System.currentTimeMillis() - t0;
+ long totalBytes = data.length * (long) repetitions;
+
+ double mbPerSec = (totalBytes / 1024.0 / 1024) / (dt / 1000.0);
+
+ System.out.println(dt + " ms");
+ System.out.println(totalBytes + " bytes");
+ System.out.println(mbPerSec + " mb/sec");
+ }
+
+ private static byte[] initData(int size) {
+ Random random = new Random(size);
+ byte[] data = new byte[size];
+ random.nextBytes(data);
+ return data;
+ }
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org