dlmarion commented on issue #2165:
URL: https://github.com/apache/accumulo/issues/2165#issuecomment-895487731


   Suggest taking a look at JMH for writing a Java benchmark.
   https://github.com/openjdk/jmh
   
   On Mon, Aug 9, 2021 at 3:19 PM Dom G. ***@***.***> wrote:
   
   > I set up some crude performance tests to see what the difference is
   > between the normal byte streams and the Unsynchronized variants. From what
   > I can tell the Unsynchronized byte streams are slower. I set up identical
   > loops in which I created a UnsynchronizedByteArrayOutputStream/
   > ByteArrayOutputStream wraped it in a DataOutputStream then wrote to it
   > (String, int and double each tested separately). Then created a
   > ByteArrayInputStream/UnsynchronizedByteArrayInputStream wraped in a
   > DataInputStream and read from it, asserting that the sent and received
   > data matched each time. From my data the Unsynchronized version ran on
   > average ~60ms where as the regular streams ran at an average of ~45ms.
   > Below is the code I used to test.
   > Code
   >
   >   @Test
   >   public void testUnsyncEncodeDecode() throws IOException {
   >     long start = System.currentTimeMillis();
   >     for (int i = 0; i < 10_000; i++) {
   >       try (UnsynchronizedByteArrayOutputStream baos = new 
UnsynchronizedByteArrayOutputStream();
   >           DataOutputStream dos = new DataOutputStream(baos)) {
   >         String out = getRandomString();
   >         dos.writeUTF(out);
   >         try (
   >             UnsynchronizedByteArrayInputStream bais =
   >                 new UnsynchronizedByteArrayInputStream(baos.toByteArray());
   >             DataInputStream dis = new DataInputStream(bais)) {
   >           String in = dis.readUTF();
   >           assertEquals(in, out);
   >         }
   >       }
   >       try (UnsynchronizedByteArrayOutputStream baos = new 
UnsynchronizedByteArrayOutputStream();
   >           DataOutputStream dos = new DataOutputStream(baos)) {
   >         int out = random.nextInt();
   >         dos.writeInt(out);
   >         try (
   >             UnsynchronizedByteArrayInputStream bais =
   >                 new UnsynchronizedByteArrayInputStream(baos.toByteArray());
   >             DataInputStream dis = new DataInputStream(bais)) {
   >           int in = dis.readInt();
   >           assertEquals(in, out);
   >         }
   >       }
   >       try (UnsynchronizedByteArrayOutputStream baos = new 
UnsynchronizedByteArrayOutputStream();
   >           DataOutputStream dos = new DataOutputStream(baos)) {
   >         double out = random.nextDouble();
   >         dos.writeDouble(out);
   >         try (
   >             UnsynchronizedByteArrayInputStream bais =
   >                 new UnsynchronizedByteArrayInputStream(baos.toByteArray());
   >             DataInputStream dis = new DataInputStream(bais)) {
   >           double in = dis.readDouble();
   >           assertEquals(in, out, 0.001);
   >         }
   >       }
   >     }
   >     long finish = System.currentTimeMillis();
   >     System.out.println("time taken: " + (finish - start));
   >   }
   >
   >   @Test
   >   public void testClassicEncodeDecode() throws IOException {
   >     long start = System.currentTimeMillis();
   >     for (int i = 0; i < 10_000; i++) {
   >       try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
   >           DataOutputStream dos = new DataOutputStream(baos)) {
   >         String out = getRandomString();
   >         dos.writeUTF(out);
   >         try (ByteArrayInputStream bais = new 
ByteArrayInputStream(baos.toByteArray());
   >             DataInputStream dis = new DataInputStream(bais)) {
   >           String in = dis.readUTF();
   >           assertEquals(in, out);
   >         }
   >       }
   >       try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
   >           DataOutputStream dos = new DataOutputStream(baos)) {
   >         int out = random.nextInt();
   >         dos.writeInt(out);
   >         try (ByteArrayInputStream bais = new 
ByteArrayInputStream(baos.toByteArray());
   >             DataInputStream dis = new DataInputStream(bais)) {
   >           int in = dis.readInt();
   >           assertEquals(in, out);
   >         }
   >       }
   >       try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
   >           DataOutputStream dos = new DataOutputStream(baos)) {
   >         double out = random.nextDouble();
   >         dos.writeDouble(out);
   >         try (ByteArrayInputStream bais = new 
ByteArrayInputStream(baos.toByteArray());
   >             DataInputStream dis = new DataInputStream(bais)) {
   >           double in = dis.readDouble();
   >           assertEquals(in, out, 0.001);
   >         }
   >       }
   >     }
   >     long finish = System.currentTimeMillis();
   >     System.out.println("time taken: " + (finish - start));
   >   }
   >
   > I'm not sure if this kind of testing is helpful, just thought I would pass
   > along my findings.
   >
   > —
   > You are receiving this because you are subscribed to this thread.
   > Reply to this email directly, view it on GitHub
   > <https://github.com/apache/accumulo/issues/2165#issuecomment-895476936>,
   > or unsubscribe
   > 
<https://github.com/notifications/unsubscribe-auth/AAEKUZZDJQPEFWD44YZKM3TT4AS3NANCNFSM46XLZSTA>
   > .
   > Triage notifications on the go with GitHub Mobile for iOS
   > 
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
   > or Android
   > 
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
   > .
   >
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to