22
33
44import com .dslplatform .json .DslJson ;
5+ import com .dslplatform .json .JsonWriter ;
6+ import com .dslplatform .json .NumberConverter ;
57import com .fasterxml .jackson .core .JsonGenerator ;
68import com .fasterxml .jackson .databind .ObjectMapper ;
9+ import com .jsoniter .annotation .JsonWrapper ;
710import com .jsoniter .output .JsonStream ;
811import org .junit .Test ;
912import org .openjdk .jmh .Main ;
1013import org .openjdk .jmh .annotations .*;
1114import org .openjdk .jmh .infra .BenchmarkParams ;
15+ import org .openjdk .jmh .infra .Blackhole ;
1216
1317import java .io .ByteArrayOutputStream ;
1418import java .io .IOException ;
@@ -21,24 +25,26 @@ public class IntegerOutput {
2125 private JsonStream stream ;
2226 private byte [] buffer ;
2327 private DslJson dslJson ;
28+ private JsonWriter jsonWriter ;
2429
2530 public static void main (String [] args ) throws Exception {
2631 Main .main (new String []{
2732 "IntegerOutput" ,
2833 "-i" , "5" ,
2934 "-wi" , "5" ,
3035 "-f" , "1" ,
36+ "-prof" , "stack"
3137 });
3238 }
3339
3440 @ Test
3541 public void test () throws IOException {
3642 benchSetup (null );
37- jsoniter ();
43+ jsoniter (null );
3844 System .out .println (baos .toString ());
3945 jackson ();
4046 System .out .println (baos .toString ());
41- dsljson ();
47+ dsljson (null );
4248 System .out .println (baos .toString ());
4349 }
4450
@@ -50,14 +56,16 @@ public void benchSetup(BenchmarkParams params) {
5056 stream = new JsonStream (baos , 4096 );
5157 buffer = new byte [4096 ];
5258 dslJson = new DslJson ();
59+ jsonWriter = new JsonWriter ();
5360 }
5461
5562 @ Benchmark
56- public void jsoniter () throws IOException {
63+ public void jsoniter (Blackhole bh ) throws IOException {
5764 baos .reset ();
5865 stream .reset (baos );
5966 stream .writeVal (1024 );
6067 stream .flush ();
68+ // bh.consume(stream);
6169 }
6270
6371 @ Benchmark
@@ -66,9 +74,12 @@ public void jackson() throws IOException {
6674 objectMapper .writeValue (baos , 1024 );
6775 }
6876
69- @ Benchmark
70- public void dsljson () throws IOException {
71- baos .reset ();
72- dslJson .serialize (1024 , baos );
77+ // @Benchmark
78+ public void dsljson (Blackhole bh ) throws IOException {
79+ // baos.reset();
80+ jsonWriter .reset ();
81+ NumberConverter .serialize (1024 , jsonWriter );
82+ // bh.consume(jsonWriter);
83+ // jsonWriter.toStream(baos);
7384 }
7485}
0 commit comments