Skip to content

Commit 5e130a9

Browse files
committed
Merge pull request #311 from msgpack/v07-test-various-str-len
Test various lengths of String in MessagePackDataformatPojoBenchmarkTest
2 parents 97e9599 + 3ba973b commit 5e130a9

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

msgpack-jackson/src/test/java/org/msgpack/jackson/dataformat/benchmark/MessagePackDataformatPojoBenchmarkTest.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,33 @@
3232

3333
public class MessagePackDataformatPojoBenchmarkTest
3434
{
35-
private static final int LOOP_MAX = 600;
36-
private static final int LOOP_FACTOR = 40;
35+
private static final int LOOP_MAX = 200;
36+
private static final int LOOP_FACTOR_SER = 40;
37+
private static final int LOOP_FACTOR_DESER = 200;
3738
private static final int COUNT = 6;
3839
private static final int WARMUP_COUNT = 4;
39-
private static final List<NormalPojo> pojos = new ArrayList<NormalPojo>(LOOP_MAX);
40-
private static final List<byte[]> pojosSerWithOrig = new ArrayList<byte[]>(LOOP_MAX);
41-
private static final List<byte[]> pojosSerWithMsgPack = new ArrayList<byte[]>(LOOP_MAX);
40+
private final List<NormalPojo> pojos = new ArrayList<NormalPojo>(LOOP_MAX);
41+
private final List<byte[]> pojosSerWithOrig = new ArrayList<byte[]>(LOOP_MAX);
42+
private final List<byte[]> pojosSerWithMsgPack = new ArrayList<byte[]>(LOOP_MAX);
4243
private final ObjectMapper origObjectMapper = new ObjectMapper();
4344
private final ObjectMapper msgpackObjectMapper = new ObjectMapper(new MessagePackFactory());
4445

45-
static {
46-
final ObjectMapper origObjectMapper = new ObjectMapper();
47-
final ObjectMapper msgpackObjectMapper = new ObjectMapper(new MessagePackFactory());
46+
public MessagePackDataformatPojoBenchmarkTest()
47+
{
48+
origObjectMapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
49+
msgpackObjectMapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
4850

4951
for (int i = 0; i < LOOP_MAX; i++) {
5052
NormalPojo pojo = new NormalPojo();
5153
pojo.i = i;
5254
pojo.l = i;
5355
pojo.f = Float.valueOf(i);
5456
pojo.d = Double.valueOf(i);
55-
pojo.setS(String.valueOf(i));
57+
StringBuilder sb = new StringBuilder();
58+
for (int sbi = 0; sbi < i * 50; sbi++) {
59+
sb.append("x");
60+
}
61+
pojo.setS(sb.toString());
5662
pojo.bool = i % 2 == 0;
5763
pojo.bi = BigInteger.valueOf(i);
5864
switch (i % 4) {
@@ -78,7 +84,7 @@ public class MessagePackDataformatPojoBenchmarkTest
7884
pojosSerWithOrig.add(origObjectMapper.writeValueAsBytes(pojos.get(i)));
7985
}
8086
catch (JsonProcessingException e) {
81-
e.printStackTrace();
87+
throw new RuntimeException("Failed to create test data");
8288
}
8389
}
8490

@@ -87,17 +93,11 @@ public class MessagePackDataformatPojoBenchmarkTest
8793
pojosSerWithMsgPack.add(msgpackObjectMapper.writeValueAsBytes(pojos.get(i)));
8894
}
8995
catch (JsonProcessingException e) {
90-
e.printStackTrace();
96+
throw new RuntimeException("Failed to create test data");
9197
}
9298
}
9399
}
94100

95-
public MessagePackDataformatPojoBenchmarkTest()
96-
{
97-
origObjectMapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
98-
msgpackObjectMapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
99-
}
100-
101101
@Test
102102
public void testBenchmark()
103103
throws Exception
@@ -117,7 +117,7 @@ public void testBenchmark()
117117
public void run()
118118
throws Exception
119119
{
120-
for (int j = 0; j < LOOP_FACTOR; j++) {
120+
for (int j = 0; j < LOOP_FACTOR_SER; j++) {
121121
for (int i = 0; i < LOOP_MAX; i++) {
122122
origObjectMapper.writeValue(outputStreamJackson, pojos.get(i));
123123
}
@@ -130,7 +130,7 @@ public void run()
130130
public void run()
131131
throws Exception
132132
{
133-
for (int j = 0; j < LOOP_FACTOR; j++) {
133+
for (int j = 0; j < LOOP_FACTOR_SER; j++) {
134134
for (int i = 0; i < LOOP_MAX; i++) {
135135
msgpackObjectMapper.writeValue(outputStreamMsgpack, pojos.get(i));
136136
}
@@ -143,7 +143,7 @@ public void run()
143143
public void run()
144144
throws Exception
145145
{
146-
for (int j = 0; j < LOOP_FACTOR; j++) {
146+
for (int j = 0; j < LOOP_FACTOR_DESER; j++) {
147147
for (int i = 0; i < LOOP_MAX; i++) {
148148
origObjectMapper.readValue(pojosSerWithOrig.get(i), NormalPojo.class);
149149
}
@@ -156,7 +156,7 @@ public void run()
156156
public void run()
157157
throws Exception
158158
{
159-
for (int j = 0; j < LOOP_FACTOR; j++) {
159+
for (int j = 0; j < LOOP_FACTOR_DESER; j++) {
160160
for (int i = 0; i < LOOP_MAX; i++) {
161161
msgpackObjectMapper.readValue(pojosSerWithMsgPack.get(i), NormalPojo.class);
162162
}

0 commit comments

Comments
 (0)