1515//
1616package org .msgpack .jackson .dataformat .benchmark ;
1717
18+ import com .fasterxml .jackson .core .JsonGenerator ;
1819import com .fasterxml .jackson .core .JsonProcessingException ;
1920import com .fasterxml .jackson .databind .ObjectMapper ;
2021import org .junit .Test ;
2122import org .msgpack .jackson .dataformat .MessagePackFactory ;
2223import static org .msgpack .jackson .dataformat .MessagePackDataformatTestBase .NormalPojo ;
2324import static org .msgpack .jackson .dataformat .MessagePackDataformatTestBase .Suit ;
2425
26+ import java .io .File ;
27+ import java .io .FileOutputStream ;
28+ import java .io .OutputStream ;
2529import java .math .BigInteger ;
2630import java .util .ArrayList ;
2731import java .util .List ;
@@ -88,20 +92,34 @@ public class MessagePackDataformatPojoBenchmarkTest
8892 }
8993 }
9094
95+ public MessagePackDataformatPojoBenchmarkTest ()
96+ {
97+ origObjectMapper .configure (JsonGenerator .Feature .AUTO_CLOSE_TARGET , false );
98+ msgpackObjectMapper .configure (JsonGenerator .Feature .AUTO_CLOSE_TARGET , false );
99+ }
100+
91101 @ Test
92102 public void testBenchmark ()
93103 throws Exception
94104 {
95105 Benchmarker benchmarker = new Benchmarker ();
96106
107+ File tempFileJackson = File .createTempFile ("msgpack-jackson-" , "-huge-jackson" );
108+ tempFileJackson .deleteOnExit ();
109+ final OutputStream outputStreamJackson = new FileOutputStream (tempFileJackson );
110+
111+ File tempFileMsgpack = File .createTempFile ("msgpack-jackson-" , "-huge-msgpack" );
112+ tempFileMsgpack .deleteOnExit ();
113+ final OutputStream outputStreamMsgpack = new FileOutputStream (tempFileMsgpack );
114+
97115 benchmarker .addBenchmark (new Benchmarker .Benchmarkable ("serialize(pojo) with JSON" ) {
98116 @ Override
99117 public void run ()
100118 throws Exception
101119 {
102120 for (int j = 0 ; j < LOOP_FACTOR ; j ++) {
103121 for (int i = 0 ; i < LOOP_MAX ; i ++) {
104- origObjectMapper .writeValueAsBytes ( pojos .get (i ));
122+ origObjectMapper .writeValue ( outputStreamJackson , pojos .get (i ));
105123 }
106124 }
107125 }
@@ -114,7 +132,7 @@ public void run()
114132 {
115133 for (int j = 0 ; j < LOOP_FACTOR ; j ++) {
116134 for (int i = 0 ; i < LOOP_MAX ; i ++) {
117- msgpackObjectMapper .writeValueAsBytes ( pojos .get (i ));
135+ msgpackObjectMapper .writeValue ( outputStreamMsgpack , pojos .get (i ));
118136 }
119137 }
120138 }
@@ -146,6 +164,12 @@ public void run()
146164 }
147165 });
148166
149- benchmarker .run (COUNT , WARMUP_COUNT );
167+ try {
168+ benchmarker .run (COUNT , WARMUP_COUNT );
169+ }
170+ finally {
171+ outputStreamJackson .close ();
172+ outputStreamMsgpack .close ();
173+ }
150174 }
151175}
0 commit comments