PROTON-1911: add JMH test of encoding message with various elements of string metadata and payload
diff --git a/tests/performance-jmh/src/main/java/org/apache/qpid/proton/message/StringsBenchmark.java b/tests/performance-jmh/src/main/java/org/apache/qpid/proton/message/StringsBenchmark.java
index 00a92cc..77f70a8 100644
--- a/tests/performance-jmh/src/main/java/org/apache/qpid/proton/message/StringsBenchmark.java
+++ b/tests/performance-jmh/src/main/java/org/apache/qpid/proton/message/StringsBenchmark.java
@@ -17,6 +17,7 @@
package org.apache.qpid.proton.message;
+import org.apache.qpid.proton.amqp.messaging.AmqpValue;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.infra.Blackhole;
@@ -26,18 +27,27 @@
public class StringsBenchmark extends MessageBenchmark
{
+ private static final String PAYLOAD = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
+ + "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
private Blackhole blackhole;
private String string1;
private String string2;
private String string3;
+ private Message message;
+ private byte[] buffer = new byte[8096];
+
@Setup
public void init(Blackhole blackhole)
{
this.blackhole = blackhole;
super.init();
initStrings();
+ initStringMessage();
encode();
}
@@ -48,6 +58,15 @@
string3 = new String("String-3");
}
+ private void initStringMessage()
+ {
+ message = Message.Factory.create();
+ message.setAddress("destination");
+ message.setMessageId("my-message-id");
+ message.setReplyTo("reply-destination");
+ message.setBody(new AmqpValue(PAYLOAD));
+ }
+
@Benchmark
@Override
public ByteBuffer encode()
@@ -70,6 +89,13 @@
return byteBuf;
}
+ @Benchmark
+ public byte[] encodeStringMessage()
+ {
+ message.encode(buffer, 0, buffer.length);
+ return buffer;
+ }
+
public static void main(String[] args) throws RunnerException
{
runBenchmark(StringsBenchmark.class);