Skip to content

Commit 5f9341f

Browse files
committed
InputStream test. Updated readme.
Add missing test for reading off InputStream. Updated DSL-JSON to v1.0 Updated README with latest run.
1 parent 2cdcc34 commit 5f9341f

22 files changed

+273
-34
lines changed

README.md

Lines changed: 81 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -108,37 +108,43 @@ Results as reported on console, except sorted in descending order of performance
108108
```
109109
% java -Xmx256m -jar target/microbenchmarks.jar ".*DZoneWrite.*write1k.*AsString.*" -wi 4 -i 5 -f 19
110110
111-
# Run complete. Total time: 00:20:58
111+
# Run complete. Total time: 00:29:51
112112
113113
Benchmark Mode Cnt Score Error Units
114-
DZoneWriteJackson.write1kAsString thrpt 95 4377.870 ± 22.375 ops/s
115-
DZoneWriteJacksonJr.write1kAsString thrpt 95 3880.734 ± 32.488 ops/s
116-
DZoneWriteBoon.write1kAsString thrpt 95 2614.780 ± 15.105 ops/s
117-
DZoneWriteJohnzon.write1kAsString thrpt 95 2088.878 ± 12.612 ops/s
118-
DZoneWriteMoshi.write1kAsString thrpt 95 1655.735 ± 9.793 ops/s
119-
DZoneWriteGSON.write1kAsString thrpt 95 1209.408 ± 10.565 ops/s
120-
DZoneWriteJsonIO.write1kAsString thrpt 95 883.185 ± 7.002 ops/s
114+
DZoneWriteDslJson.write1kAsString thrpt 95 6222.612 ± 49.992 ops/s
115+
DZoneWriteFastjson.write1kAsString thrpt 95 4256.503 ± 21.408 ops/s
116+
DZoneWriteJacksonAB.write1kAsString thrpt 95 3898.636 ± 33.145 ops/s
117+
DZoneWriteJackson.write1kAsString thrpt 95 3386.443 ± 66.570 ops/s
118+
DZoneWriteJacksonJr.write1kAsString thrpt 95 3182.897 ± 29.049 ops/s
119+
DZoneWriteBoon.write1kAsString thrpt 95 2300.457 ± 59.546 ops/s
120+
DZoneWriteJohnzon.write1kAsString thrpt 95 1528.370 ± 24.255 ops/s
121+
DZoneWriteMoshi.write1kAsString thrpt 95 1437.739 ± 22.236 ops/s
122+
DZoneWriteGSON.write1kAsString thrpt 95 1057.819 ± 10.063 ops/s
123+
DZoneWriteJsonIO.write1kAsString thrpt 95 671.863 ± 14.453 ops/s
121124
```
122125

123-
Given that the test measures throughput, Jackson (the fastest) is about 5x as fast as json.io (the slowest) for this test.
126+
Given that the test measures throughput, DSL-JSON (the fastest) is about 10x as fast as json.io (the slowest) for this test.
124127

125-
#### Reading 1000 item (POJO) list from String
128+
#### Reading 10 item (POJO) list from String
126129

127130
```
128131
% java -Xmx256m -jar target/microbenchmarks.jar ".*DZoneReadPojo.*read10FromString.*" -wi 4 -i 5 -f 9
129132
130-
# Run complete. Total time: 00:10:27
133+
# Run complete. Total time: 00:13:52
131134
132135
Benchmark Mode Cnt Score Error Units
133-
DZoneReadPojoJacksonJr.read10FromString thrpt 45 217944.421 ± 3606.032 ops/s
134-
DZoneReadPojoJackson.read10FromString thrpt 45 215162.661 ± 3699.385 ops/s
135-
DZoneReadPojoGSON.read10FromString thrpt 45 143185.788 ± 3431.425 ops/s
136-
DZoneReadPojoBoon.read10FromString thrpt 45 118542.144 ± 1747.026 ops/s
137-
DZoneReadPojoMoshi.read10FromString thrpt 45 92379.201 ± 1415.529 ops/s
138-
DZoneReadPojoJohnzon.read10FromString thrpt 45 74268.988 ± 1505.027 ops/s
136+
DZoneReadPojoDslJson.read10FromString thrpt 45 233152.796 ± 2513.390 ops/s
137+
DZoneReadPojoJacksonAB.read10FromString thrpt 45 188005.499 ± 5640.662 ops/s
138+
DZoneReadPojoJacksonJr.read10FromString thrpt 45 176081.143 ± 3220.812 ops/s
139+
DZoneReadPojoJackson.read10FromString thrpt 45 171522.616 ± 1614.882 ops/s
140+
DZoneReadPojoFastjson.read10FromString thrpt 45 165517.191 ± 2058.242 ops/s
141+
DZoneReadPojoGSON.read10FromString thrpt 45 126607.540 ± 4538.410 ops/s
142+
DZoneReadPojoBoon.read10FromString thrpt 45 92211.900 ± 596.884 ops/s
143+
DZoneReadPojoJohnzon.read10FromString thrpt 45 70438.271 ± 865.507 ops/s
144+
DZoneReadPojoMoshi.read10FromString thrpt 45 73756.350 ± 932.405 ops/s
139145
```
140146

141-
And in this case, Jackson is 50% faster than GSON, twice as fast as Moshi and triple Johnzon speed.
147+
And in this case, DSL-JSON is 20% faster than Jackson which is 50% faster than GSON, twice as fast as Boon and triple Johnzon speed.
142148

143149
Json-io is not (yet) included because it seems to require JSON content to be specifically written by `json-io`
144150
itself, and not accept standard json representation (probably since it requires type information embedded).
@@ -148,20 +154,67 @@ itself, and not accept standard json representation (probably since it requires
148154
```
149155
% java -Xmx256m -jar target/microbenchmarks.jar ".*DZoneReadMap.*read10FromString.*" -wi 4 -i 5 -f 9
150156
151-
# Run complete. Total time: 00:10:26
157+
# Run complete. Total time: 00:15:16
152158
153159
Benchmark Mode Cnt Score Error Units
154-
DZoneReadMapJacksonJr.read10FromString thrpt 45 233240.208 ± 2844.701 ops/s
155-
DZoneReadMapBoon.read10FromString thrpt 45 216714.713 ± 2328.799 ops/s
156-
DZoneReadMapJackson.read10FromString thrpt 45 197597.668 ± 2092.722 ops/s
157-
DZoneReadMapGSON.read10FromString thrpt 45 154916.876 ± 1355.639 ops/s
158-
DZoneReadMapJohnzon.read10FromString thrpt 45 75610.515 ± 469.744 ops/s
159-
DZoneReadMapJsonIO.read10FromString thrpt 45 28445.343 ± 279.304 ops/s
160-
DZoneReadMapJsonMoshi.read10FromString thrpt 45 86168.309 ± 1428.668 ops/s
160+
DZoneReadMapJacksonJr.read10FromString thrpt 45 183788.845 ± 1926.758 ops/s
161+
DZoneReadMapFastjson.read10FromString thrpt 45 172123.796 ± 1628.945 ops/s
162+
DZoneReadMapJackson.read10FromString thrpt 45 169171.957 ± 1678.742 ops/s
163+
DZoneReadMapBoon.read10FromString thrpt 45 151415.861 ± 1471.262 ops/s
164+
DZoneReadMapDslJson.read10FromString thrpt 45 144000.109 ± 2528.670 ops/s
165+
DZoneReadMapGSON.read10FromString thrpt 45 136533.317 ± 5371.167 ops/s
166+
DZoneReadMapJsonMoshi.read10FromString thrpt 45 72646.224 ± 738.465 ops/s
167+
DZoneReadMapJsonParse.read10FromString thrpt 45 65851.568 ± 356.922 ops/s
168+
DZoneReadMapJohnzon.read10FromString thrpt 45 64726.343 ± 355.917 ops/s
169+
DZoneReadMapJsonIO.read10FromString thrpt 45 29088.020 ± 625.932 ops/s
161170
```
162171

163-
In this test, `Boon` has performance slightly exceeding standard Jackson (and only slightly
164-
below `jackson-jr`); GSON coming in relatively close, and other options being significantly
172+
In this test, `Fastjson` has performance slightly exceeding standard Jackson (and only slightly
173+
below `jackson-jr`); GSON and Boon coming in relatively close, and other options being significantly
165174
slower.
166175

167176
Boon seems to specifically optimized for the combination of "untyped" (Lists, Maps) result, and use of `String` as input. In fact, with bigger input size, `Boon` is the fastest library.
177+
178+
#### Writing 1000 item (POJO) list to Stream
179+
180+
```
181+
% java -Xmx256m -jar target/microbenchmarks.jar ".*DZoneWrite.*write1kUsingStream" -wi 4 -i 5 -f 9
182+
183+
# Run complete. Total time: 00:14:09
184+
185+
Benchmark Mode Cnt Score Error Units
186+
DZoneWriteDslJson.write1kUsingStream thrpt 45 11059.275 ± 71.957 ops/s
187+
DZoneWriteJacksonAB.write1kUsingStream thrpt 45 4839.274 ± 58.191 ops/s
188+
DZoneWriteJackson.write1kUsingStream thrpt 45 3943.914 ± 56.247 ops/s
189+
DZoneWriteFastjson.write1kUsingStream thrpt 45 3619.340 ± 23.558 ops/s
190+
DZoneWriteJacksonJr.write1kUsingStream thrpt 45 3500.094 ± 114.309 ops/s
191+
DZoneWriteBoon.write1kUsingStream thrpt 45 1985.888 ± 75.288 ops/s
192+
DZoneWriteJohnzon.write1kUsingStream thrpt 45 1602.113 ± 18.489 ops/s
193+
DZoneWriteMoshi.write1kUsingStream thrpt 45 1282.247 ± 24.045 ops/s
194+
DZoneWriteJsonIO.write1kUsingStream thrpt 45 813.591 ± 23.716 ops/s
195+
DZoneWriteGSON.write1kUsingStream thrpt 45 542.166 ± 14.094 ops/s
196+
```
197+
198+
DSL-JSON is much faster when using Stream instead of String. Up to 20x difference than GSON.
199+
200+
201+
#### Read 1000 item (POJO) list from Stream
202+
203+
```
204+
% java -Xmx256m -jar target/microbenchmarks.jar ".*DZoneReadPojo.*read1kFromStream.*” -wi 4 -i 5 -f 9
205+
206+
# Run complete. Total time: 00:13:51
207+
208+
Benchmark Mode Cnt Score Error Units
209+
DZoneReadPojoDslJson.read1kFromStream thrpt 45 3054.305 ± 92.445 ops/s
210+
DZoneReadPojoJacksonAB.read1kFromStream thrpt 45 2449.244 ± 40.747 ops/s
211+
DZoneReadPojoJacksonJr.read1kFromStream thrpt 45 1982.046 ± 16.049 ops/s
212+
DZoneReadPojoJackson.read1kFromStream thrpt 45 1955.585 ± 22.946 ops/s
213+
DZoneReadPojoFastjson.read1kFromStream thrpt 45 1450.955 ± 9.774 ops/s
214+
DZoneReadPojoBoon.read1kFromStream thrpt 45 1300.449 ± 81.215 ops/s
215+
DZoneReadPojoGSON.read1kFromStream thrpt 45 1176.733 ± 14.119 ops/s
216+
DZoneReadPojoJohnzon.read1kFromStream thrpt 45 651.262 ± 41.751 ops/s
217+
DZoneReadPojoMoshi.read1kFromStream thrpt 45 639.329 ± 22.281 ops/s
218+
```
219+
220+
DSL-JSON is around 20% faster than Jackson and 5x faster then slowest (Moshi) which doesn’t support Stream input.

pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,22 @@
146146
<dependency>
147147
<groupId>com.dslplatform</groupId>
148148
<artifactId>dsl-json</artifactId>
149-
<version>0.9.5</version>
149+
<version>1.0.0</version>
150150
</dependency>
151151

152152
<dependency>
153153
<groupId>com.dslplatform</groupId>
154154
<artifactId>dsl-json-processor</artifactId>
155-
<version>0.4</version>
155+
<version>1.0</version>
156156
<scope>provided</scope>
157157
</dependency>
158158

159+
<dependency>
160+
<groupId>commons-io</groupId>
161+
<artifactId>commons-io</artifactId>
162+
<version>2.5</version>
163+
</dependency>
164+
159165
</dependencies>
160166

161167
<build>

src/main/java/com/cowtowncoder/jsonperf/dzone/read/DZoneReadMapBoon.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cowtowncoder.jsonperf.dzone.read;
22

3+
import java.io.InputStream;
34
import java.util.Map;
45
import java.util.concurrent.TimeUnit;
56

@@ -26,6 +27,11 @@ public Map<?,?> _readItems(byte[] input) throws Exception {
2627
return mapper.readValue(input, Map.class);
2728
}
2829

30+
@Override
31+
public Map<?,?> _readItems(InputStream input) throws Exception {
32+
return mapper.readValue(input, Map.class);
33+
}
34+
2935
@Override
3036
public Map<?,?> _readItems(String input) throws Exception {
3137
return mapper.readValue(input, Map.class);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.cowtowncoder.jsonperf.dzone.read;
2+
3+
import com.dslplatform.json.DslJson;
4+
import org.openjdk.jmh.annotations.OutputTimeUnit;
5+
import org.openjdk.jmh.annotations.Scope;
6+
import org.openjdk.jmh.annotations.State;
7+
8+
import java.io.InputStream;
9+
import java.util.Map;
10+
import java.util.concurrent.TimeUnit;
11+
12+
@State(Scope.Thread)
13+
@OutputTimeUnit(TimeUnit.SECONDS)
14+
public class DZoneReadMapDslJson extends DZoneReadTestBase<Map<String, Object>>
15+
{
16+
private final DslJson<Object> dsl;
17+
private final byte[] buffer = new byte[8196];
18+
19+
public DZoneReadMapDslJson()
20+
{
21+
dsl = new DslJson<>();
22+
}
23+
24+
@SuppressWarnings("unchecked")
25+
@Override
26+
public Map<String, Object> _readItems(byte[] input) throws Exception {
27+
return dsl.deserialize(Map.class, input, input.length);
28+
}
29+
30+
@SuppressWarnings("unchecked")
31+
@Override
32+
public Map<String, Object> _readItems(InputStream input) throws Exception {
33+
return dsl.deserialize(Map.class, input, buffer);
34+
}
35+
36+
@Override
37+
public Map<String, Object> _readItems(String input) throws Exception {
38+
return _readItems(input.getBytes("UTF-8"));
39+
}
40+
}

src/main/java/com/cowtowncoder/jsonperf/dzone/read/DZoneReadMapFastjson.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cowtowncoder.jsonperf.dzone.read;
22

3+
import java.io.InputStream;
34
import java.util.Map;
45
import java.util.concurrent.TimeUnit;
56

@@ -25,6 +26,12 @@ public Map<Object,Object> _readItems(byte[] input) throws Exception {
2526
return (Map<Object,Object>) JSON.parse(input, Feature.DisableCircularReferenceDetect);
2627
}
2728

29+
@SuppressWarnings("unchecked")
30+
@Override
31+
public Map<Object,Object> _readItems(InputStream input) throws Exception {
32+
return (Map<Object,Object>) JSON.parseObject(input, Map.class, Feature.DisableCircularReferenceDetect);
33+
}
34+
2835
@SuppressWarnings("unchecked")
2936
@Override
3037
public Map<Object,Object> _readItems(String input) throws Exception {

src/main/java/com/cowtowncoder/jsonperf/dzone/read/DZoneReadMapGSON.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ public DZoneReadMapGSON()
2424

2525
@Override
2626
public Map<?,?> _readItems(byte[] input) throws Exception {
27-
InputStreamReader r = new InputStreamReader(new ByteArrayInputStream(input), "UTF-8");
27+
return _readItems(new ByteArrayInputStream(input));
28+
}
29+
30+
@Override
31+
public Map<?,?> _readItems(InputStream input) throws Exception {
32+
InputStreamReader r = new InputStreamReader(input, "UTF-8");
2833
Map<?,?> value = gson.fromJson(r, Map.class);
2934
r.close();
3035
return value;

src/main/java/com/cowtowncoder/jsonperf/dzone/read/DZoneReadMapJackson.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cowtowncoder.jsonperf.dzone.read;
22

3+
import java.io.InputStream;
34
import java.util.Map;
45
import java.util.concurrent.TimeUnit;
56

@@ -26,6 +27,11 @@ public Map<Object,Object> _readItems(byte[] input) throws Exception {
2627
return objectReader.readValue(input);
2728
}
2829

30+
@Override
31+
public Map<Object,Object> _readItems(InputStream input) throws Exception {
32+
return objectReader.readValue(input);
33+
}
34+
2935
@Override
3036
public Map<Object,Object> _readItems(String input) throws Exception {
3137
return objectReader.readValue(input);

src/main/java/com/cowtowncoder/jsonperf/dzone/read/DZoneReadMapJacksonJr.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cowtowncoder.jsonperf.dzone.read;
22

3+
import java.io.InputStream;
34
import java.util.Map;
45
import java.util.concurrent.TimeUnit;
56

@@ -25,6 +26,11 @@ public Map<?,?> _readItems(byte[] input) throws Exception {
2526
return json.mapFrom(input);
2627
}
2728

29+
@Override
30+
public Map<?,?> _readItems(InputStream input) throws Exception {
31+
return json.mapFrom(input);
32+
}
33+
2834
@Override
2935
public Map<?,?> _readItems(String input) throws Exception {
3036
return json.mapFrom(input);

src/main/java/com/cowtowncoder/jsonperf/dzone/read/DZoneReadMapJohnzon.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.cowtowncoder.jsonperf.dzone.read;
22

33
import java.io.ByteArrayInputStream;
4+
import java.io.InputStream;
45
import java.util.Map;
56
import java.util.concurrent.TimeUnit;
67

@@ -23,8 +24,13 @@ public DZoneReadMapJohnzon()
2324

2425
@Override
2526
public Map<?,?> _readItems(byte[] input) throws Exception {
27+
return _readItems(new ByteArrayInputStream(input));
28+
}
29+
30+
@Override
31+
public Map<?,?> _readItems(InputStream input) throws Exception {
2632
// force assign to ensure casting checks the type
27-
Map<?,?> value = mapper.readObject(new ByteArrayInputStream(input), Object.class);
33+
Map<?,?> value = mapper.readObject(input, Object.class);
2834
return value;
2935
}
3036

src/main/java/com/cowtowncoder/jsonperf/dzone/read/DZoneReadMapJsonIO.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ public DZoneReadMapJsonIO() { }
1818

1919
@Override
2020
public Map<?,?> _readItems(byte[] input) throws Exception {
21-
JsonReader r = new JsonReader(new ByteArrayInputStream(input));
21+
return _readItems(new ByteArrayInputStream(input));
22+
}
23+
24+
@Override
25+
public Map<?,?> _readItems(InputStream input) throws Exception {
26+
JsonReader r = new JsonReader(input);
2227
Map<?,?> value = (Map<?,?>) r.readObject();
2328
r.close();
2429
return value;

0 commit comments

Comments
 (0)