Repository: cassandra
Updated Branches:
  refs/heads/trunk cbb982cc1 -> 2f6d41633


follow up to CASSANDRA-8670, cleaning up benchmark

patch by ariel; reviewed by benedict for CASSANDRA-8670


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/2f6d4163
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/2f6d4163
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/2f6d4163

Branch: refs/heads/trunk
Commit: 2f6d416339864e336945474bbb44c90b60ea29bc
Parents: 5c55b7d
Author: Ariel Weisberg <[email protected]>
Authored: Thu Apr 9 12:09:46 2015 +0100
Committer: Benedict Elliott Smith <[email protected]>
Committed: Thu Apr 9 12:10:27 2015 +0100

----------------------------------------------------------------------
 .../test/microbench/OutputStreamBench.java      | 149 +++++++++++--------
 .../io/util/BufferedDataOutputStreamTest.java   |   9 +-
 .../io/util/NIODataInputStreamTest.java         |  21 ++-
 3 files changed, 95 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/2f6d4163/test/microbench/org/apache/cassandra/test/microbench/OutputStreamBench.java
----------------------------------------------------------------------
diff --git 
a/test/microbench/org/apache/cassandra/test/microbench/OutputStreamBench.java 
b/test/microbench/org/apache/cassandra/test/microbench/OutputStreamBench.java
index b8136f7..7a159a2 100644
--- 
a/test/microbench/org/apache/cassandra/test/microbench/OutputStreamBench.java
+++ 
b/test/microbench/org/apache/cassandra/test/microbench/OutputStreamBench.java
@@ -22,6 +22,7 @@ import 
org.apache.cassandra.io.util.BufferedDataOutputStreamPlus;
 import org.apache.cassandra.io.util.BufferedDataOutputStreamTest;
 import org.apache.cassandra.io.util.WrappedDataOutputStreamPlus;
 import org.openjdk.jmh.annotations.*;
+import org.openjdk.jmh.infra.Blackhole;
 
 import java.io.BufferedOutputStream;
 import java.io.IOException;
@@ -40,66 +41,103 @@ import java.util.concurrent.TimeUnit;
 public class OutputStreamBench
 {
 
-    BufferedOutputStream hole = new BufferedOutputStream(new OutputStream() {
+    BufferedOutputStream hole;
 
-        @Override
-        public void write(int b) throws IOException
-        {
+    WrappedDataOutputStreamPlus streamA;
 
-        }
+    BufferedDataOutputStreamPlus streamB;
 
-        @Override
-        public void write(byte b[]) throws IOException {
+    byte foo;
 
-        }
+    int foo1;
 
-        @Override
-        public void write(byte b[], int a, int c) throws IOException {
+    long foo2;
 
-        }
-        });
+    double foo3;
 
-    WrappedDataOutputStreamPlus streamA = new 
WrappedDataOutputStreamPlus(hole);
+    float foo4;
 
-    BufferedDataOutputStreamPlus streamB = new 
BufferedDataOutputStreamPlus(new WritableByteChannel() {
+    short foo5;
 
-        @Override
-        public boolean isOpen()
-        {
-            // TODO Auto-generated method stub
-            return true;
-        }
+    char foo6;
 
-        @Override
-        public void close() throws IOException
-        {
-            // TODO Auto-generated method stub
 
-        }
+    String tinyM = BufferedDataOutputStreamTest.fourByte;
+    String smallM;
+    String largeM;
+    String tiny = "a";
+    String small = 
"adsjglhnafsjk;gujfakyhgukafshgjkahfsgjkhafs;jkhausjkgaksfj;gafskdghajfsk;g";
+    String large;
 
-        @Override
-        public int write(ByteBuffer src) throws IOException
-        {
-            int remaining = src.remaining();
-            src.position(src.limit());
-            return remaining;
+    @Setup
+    public void setUp(final Blackhole bh) {
+        StringBuilder sb = new StringBuilder();
+        for (int ii = 0; ii < 11; ii++) {
+            sb.append(BufferedDataOutputStreamTest.fourByte);
+            sb.append(BufferedDataOutputStreamTest.threeByte);
+            sb.append(BufferedDataOutputStreamTest.twoByte);
         }
+        smallM = sb.toString();
+            
+        sb = new StringBuilder();
+        while (sb.length() < 1024 * 12) {
+            sb.append(small);
+        }
+        large = sb.toString();
 
-    }, 8192);
-
-    public static byte foo;
-
-    public static int foo1;
-
-    public static long foo2;
-
-    public static double foo3;
-
-    public static float foo4;
-
-    public static short foo5;
+        sb = new StringBuilder();
+        while (sb.length() < 1024 * 12) {
+            sb.append(smallM);
+        }
+        largeM = sb.toString();
 
-    public static char foo6;
+        hole = new BufferedOutputStream(new OutputStream() {
+
+            @Override
+            public void write(int b) throws IOException
+            {
+                bh.consume(b);
+            }
+
+            @Override
+            public void write(byte b[]) throws IOException {
+                bh.consume(b);
+            }
+
+            @Override
+            public void write(byte b[], int a, int c) throws IOException {
+                bh.consume(b);
+                bh.consume(a);
+                bh.consume(c);
+            }
+            });
+
+        streamA = new WrappedDataOutputStreamPlus(hole);
+
+        streamB = new BufferedDataOutputStreamPlus(new WritableByteChannel() {
+
+            @Override
+            public boolean isOpen()
+            {
+                return true;
+            }
+
+            @Override
+            public void close() throws IOException
+            {
+            }
+
+            @Override
+            public int write(ByteBuffer src) throws IOException
+            {
+                bh.consume(src);
+                int remaining = src.remaining();
+                src.position(src.limit());
+                return remaining;
+            }
+
+        }, 8192);
+    }
 
     @Benchmark
     public void testBOSByte() throws IOException
@@ -161,27 +199,6 @@ public class OutputStreamBench
         streamB.writeChar(foo6);
     }
 
-    public static String tinyM = "𠝹";
-    public static String smallM = "𠝹㒨ƀ𠝹㒨ƀ𠝹㒨ƀ𠝹㒨ƀð 
¹ã’¨Æ€ð ¹ã’¨Æ€ð ¹ã’¨Æ€ð ¹ã’¨Æ€ð ¹ã’¨Æ€ð ¹ã’¨Æ€ð ¹ã’¨Æ€";
-    public static String largeM;
-    public static String tiny = "a";
-    public static String small = 
"adsjglhnafsjk;gujfakyhgukafshgjkahfsgjkhafs;jkhausjkgaksfj;gafskdghajfsk;g";
-    public static String large;
-
-    static {
-        StringBuilder sb = new StringBuilder();
-        while (sb.length() < 1024 * 12) {
-            sb.append(small);
-        }
-        large = sb.toString();
-
-        sb = new StringBuilder();
-        while (sb.length() < 1024 * 12) {
-            sb.append(smallM);
-        }
-        largeM = sb.toString();
-    }
-
     @Benchmark
     public void testMTinyStringBOS() throws IOException {
         streamA.writeUTF(tinyM);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2f6d4163/test/unit/org/apache/cassandra/io/util/BufferedDataOutputStreamTest.java
----------------------------------------------------------------------
diff --git 
a/test/unit/org/apache/cassandra/io/util/BufferedDataOutputStreamTest.java 
b/test/unit/org/apache/cassandra/io/util/BufferedDataOutputStreamTest.java
index f5b239c..d0819fe 100644
--- a/test/unit/org/apache/cassandra/io/util/BufferedDataOutputStreamTest.java
+++ b/test/unit/org/apache/cassandra/io/util/BufferedDataOutputStreamTest.java
@@ -1,7 +1,6 @@
 package org.apache.cassandra.io.util;
 
 import java.io.ByteArrayOutputStream;
-import java.io.DataOutput;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.UTFDataFormatException;
@@ -13,8 +12,6 @@ import java.util.Random;
 
 import org.junit.Test;
 
-import com.google.common.base.Throwables;
-
 import static org.junit.Assert.*;
 
 public class BufferedDataOutputStreamTest
@@ -175,9 +172,9 @@ public class BufferedDataOutputStreamTest
     }
 
     String simple = "foobar42";
-    String twoByte = "ƀ";
-    String threeByte = "㒨";
-    String fourByte = "𠝹";
+    public static final String twoByte = "\u0180";
+    public static final String threeByte = "\u34A8";
+    public static final String fourByte = "\uD841\uDF79";
 
     @SuppressWarnings("unused")
     private void fuzzOnce() throws Exception

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2f6d4163/test/unit/org/apache/cassandra/io/util/NIODataInputStreamTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/util/NIODataInputStreamTest.java 
b/test/unit/org/apache/cassandra/io/util/NIODataInputStreamTest.java
index 4106036..a19346b 100644
--- a/test/unit/org/apache/cassandra/io/util/NIODataInputStreamTest.java
+++ b/test/unit/org/apache/cassandra/io/util/NIODataInputStreamTest.java
@@ -234,18 +234,15 @@ public class NIODataInputStreamTest
         DataOutputStream daos = new DataOutputStream(baos);
 
         String simple = "foobar42";
-        String twoByte = "ƀ";
-        String threeByte = "㒨";
-        String fourByte = "𠝹";
 
-        assertEquals(2, twoByte.getBytes(Charsets.UTF_8).length);
-        assertEquals(3, threeByte.getBytes(Charsets.UTF_8).length);
-        assertEquals(4, fourByte.getBytes(Charsets.UTF_8).length);
+        assertEquals(2, 
BufferedDataOutputStreamTest.twoByte.getBytes(Charsets.UTF_8).length);
+        assertEquals(3, 
BufferedDataOutputStreamTest.threeByte.getBytes(Charsets.UTF_8).length);
+        assertEquals(4, 
BufferedDataOutputStreamTest.fourByte.getBytes(Charsets.UTF_8).length);
 
         daos.writeUTF(simple);
-        daos.writeUTF(twoByte);
-        daos.writeUTF(threeByte);
-        daos.writeUTF(fourByte);
+        daos.writeUTF(BufferedDataOutputStreamTest.twoByte);
+        daos.writeUTF(BufferedDataOutputStreamTest.threeByte);
+        daos.writeUTF(BufferedDataOutputStreamTest.fourByte);
 
         NIODataInputStream is = new NIODataInputStream(new 
ReadableByteChannel()
         {
@@ -266,9 +263,9 @@ public class NIODataInputStreamTest
         }, 4096);
 
         assertEquals(simple, is.readUTF());
-        assertEquals(twoByte, is.readUTF());
-        assertEquals(threeByte, is.readUTF());
-        assertEquals(fourByte, is.readUTF());
+        assertEquals(BufferedDataOutputStreamTest.twoByte, is.readUTF());
+        assertEquals(BufferedDataOutputStreamTest.threeByte, is.readUTF());
+        assertEquals(BufferedDataOutputStreamTest.fourByte, is.readUTF());
     }
 
     @Test

Reply via email to