Skip to content

Commit 6d4310e

Browse files
committed
refactoring: try to force non-lazy Maps by calling size() on results (not much effect it seems)
1 parent a069763 commit 6d4310e

12 files changed

+140
-58
lines changed

results/results-2016-07-tatu.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,50 @@
11
Date: 13-Jul-2016 -
22
JDK: 1.8.0_92
33

4+
--- Read Map from Stream ---
5+
6+
java -Xmx256m -jar target/microbenchmarks.jar ".*DZoneReadMap.*read10FromStream.*" -wi 4 -i 5 -f 9
7+
8+
Benchmark Mode Cnt Score Error Units
9+
DZoneReadMapBoon.read10FromStream thrpt 45 110664.199 ± 1905.039 ops/s
10+
DZoneReadMapDslJson.read10FromStream thrpt 45 181647.546 ± 1876.688 ops/s
11+
DZoneReadMapFastjson.read10FromStream thrpt 45 174096.798 ± 899.883 ops/s
12+
DZoneReadMapGSON.read10FromStream thrpt 45 129327.023 ± 1056.891 ops/s
13+
DZoneReadMapJackson.read10FromStream thrpt 45 219009.268 ± 2214.295 ops/s
14+
DZoneReadMapJacksonJr.read10FromStream thrpt 45 255682.953 ± 2929.655 ops/s
15+
DZoneReadMapJohnzon.read10FromStream thrpt 45 73088.556 ± 607.049 ops/s
16+
DZoneReadMapJsonIO.read10FromStream thrpt 45 35642.339 ± 193.698 ops/s
17+
DZoneReadMapJsonMoshi.read10FromStream thrpt 45 78010.156 ± 617.661 ops/s
18+
DZoneReadMapJsonParse.read10FromStream thrpt 45 67171.690 ± 556.279 ops/s
19+
20+
java -Xmx256m -jar target/microbenchmarks.jar ".*DZoneReadMap.*read1kFromStream.*" -wi 4 -i 5 -f 9
21+
22+
Benchmark Mode Cnt Score Error Units
23+
DZoneReadMapBoon.read1kFromStream thrpt 45 2859.476 ± 17.116 ops/s
24+
DZoneReadMapDslJson.read1kFromStream thrpt 45 2100.989 ± 12.555 ops/s
25+
DZoneReadMapFastjson.read1kFromStream thrpt 45 1792.598 ± 9.966 ops/s
26+
DZoneReadMapGSON.read1kFromStream thrpt 45 1349.287 ± 27.478 ops/s
27+
DZoneReadMapJackson.read1kFromStream thrpt 45 2283.543 ± 19.933 ops/s
28+
DZoneReadMapJacksonJr.read1kFromStream thrpt 45 2627.788 ± 61.535 ops/s
29+
DZoneReadMapJohnzon.read1kFromStream thrpt 45 788.152 ± 8.899 ops/s
30+
DZoneReadMapJsonIO.read1kFromStream thrpt 45 437.401 ± 2.061 ops/s
31+
DZoneReadMapJsonMoshi.read1kFromStream thrpt 45 904.866 ± 7.869 ops/s
32+
DZoneReadMapJsonParse.read1kFromStream thrpt 45 840.337 ± 4.644 ops/s
33+
34+
java -Xmx512m -jar target/microbenchmarks.jar ".*DZoneReadMap.*read100kFromStream.*" -wi 4 -i 5 -f 1
35+
36+
Benchmark Mode Cnt Score Error Units
37+
DZoneReadMapBoon.read100kFromStream thrpt 5 5.207 ± 4.223 ops/s
38+
DZoneReadMapDslJson.read100kFromStream thrpt 5 13.378 ± 5.999 ops/s
39+
DZoneReadMapFastjson.read100kFromStream thrpt 5 11.682 ± 4.782 ops/s
40+
DZoneReadMapGSON.read100kFromStream thrpt 5 7.541 ± 5.027 ops/s
41+
DZoneReadMapJackson.read100kFromStream thrpt 5 20.383 ± 1.312 ops/s
42+
DZoneReadMapJacksonJr.read100kFromStream thrpt 5 27.478 ± 1.170 ops/s
43+
DZoneReadMapJohnzon.read100kFromStream thrpt 5 4.193 ± 1.505 ops/s
44+
DZoneReadMapJsonIO.read100kFromStream thrpt 5 2.424 ± 1.377 ops/s
45+
DZoneReadMapJsonMoshi.read100kFromStream thrpt 5 5.321 ± 0.262 ops/s
46+
DZoneReadMapJsonParse.read100kFromStream thrpt 5 3.767 ± 2.407 ops/s
47+
448
--- Read POJO from Stream ---
549

650
java -Xmx256m -jar target/microbenchmarks.jar ".*DZoneReadPojo.*read10FromStream.*" -wi 4 -i 5 -f 9
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.cowtowncoder.jsonperf.dzone;
2+
3+
import java.io.InputStream;
4+
import java.util.Map;
5+
6+
public abstract class DZoneMapReadTestBase
7+
extends DZoneReadTestBase<Map<?,?>>
8+
{
9+
@Override
10+
public Map<?,?> _readItems(byte[] input) throws Exception {
11+
Map<?,?> result = _readMap(input);
12+
// do minimal (performance-wise) access that avoids lazy loading/map-creation
13+
// (although not necessarily recursively)
14+
result.size();
15+
return result;
16+
}
17+
18+
@Override
19+
public Map<?,?> _readItems(InputStream input) throws Exception {
20+
Map<?,?> result = _readMap(input);
21+
// do minimal (performance-wise) access that avoids lazy loading/map-creation
22+
// (although not necessarily recursively)
23+
result.size();
24+
return result;
25+
}
26+
27+
@Override
28+
public Map<?,?> _readItems(String input) throws Exception {
29+
Map<?,?> result = _readMap(input);
30+
// do minimal (performance-wise) access that avoids lazy loading/map-creation
31+
// (although not necessarily recursively)
32+
result.size();
33+
return result;
34+
}
35+
36+
public abstract Map<?,?> _readMap(byte[] input) throws Exception;
37+
38+
public abstract Map<?,?> _readMap(InputStream input) throws Exception;
39+
40+
public abstract Map<?,?> _readMap(String input) throws Exception;
41+
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
import org.openjdk.jmh.annotations.Scope;
99
import org.openjdk.jmh.annotations.State;
1010

11-
import com.cowtowncoder.jsonperf.dzone.DZoneReadTestBase;
11+
import com.cowtowncoder.jsonperf.dzone.DZoneMapReadTestBase;
1212

1313
import org.boon.json.JsonFactory;
1414
import org.boon.json.ObjectMapper;
1515

1616
@State(Scope.Thread)
1717
@OutputTimeUnit(TimeUnit.SECONDS)
18-
public class DZoneReadMapBoon extends DZoneReadTestBase<Map<?,?>>
18+
public class DZoneReadMapBoon extends DZoneMapReadTestBase
1919
{
2020
protected final ObjectMapper mapper;
2121

@@ -25,17 +25,17 @@ public DZoneReadMapBoon()
2525
}
2626

2727
@Override
28-
public Map<?,?> _readItems(byte[] input) throws Exception {
28+
public Map<?,?> _readMap(byte[] input) throws Exception {
2929
return mapper.readValue(input, Map.class);
3030
}
3131

3232
@Override
33-
public Map<?,?> _readItems(InputStream input) throws Exception {
33+
public Map<?,?> _readMap(InputStream input) throws Exception {
3434
return mapper.readValue(input, Map.class);
3535
}
3636

3737
@Override
38-
public Map<?,?> _readItems(String input) throws Exception {
38+
public Map<?,?> _readMap(String input) throws Exception {
3939
return mapper.readValue(input, Map.class);
4040
}
4141
}

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

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

3-
import com.cowtowncoder.jsonperf.dzone.DZoneReadTestBase;
3+
import com.cowtowncoder.jsonperf.dzone.DZoneMapReadTestBase;
44
import com.dslplatform.json.DslJson;
55
import org.openjdk.jmh.annotations.OutputTimeUnit;
66
import org.openjdk.jmh.annotations.Scope;
@@ -12,7 +12,7 @@
1212

1313
@State(Scope.Thread)
1414
@OutputTimeUnit(TimeUnit.SECONDS)
15-
public class DZoneReadMapDslJson extends DZoneReadTestBase<Map<String, Object>>
15+
public class DZoneReadMapDslJson extends DZoneMapReadTestBase
1616
{
1717
private final DslJson<Object> dsl;
1818
private final byte[] buffer = new byte[8192];
@@ -24,18 +24,18 @@ public DZoneReadMapDslJson()
2424

2525
@SuppressWarnings("unchecked")
2626
@Override
27-
public Map<String, Object> _readItems(byte[] input) throws Exception {
27+
public Map<String, Object> _readMap(byte[] input) throws Exception {
2828
return dsl.deserialize(Map.class, input, input.length);
2929
}
3030

3131
@SuppressWarnings("unchecked")
3232
@Override
33-
public Map<String, Object> _readItems(InputStream input) throws Exception {
33+
public Map<String, Object> _readMap(InputStream input) throws Exception {
3434
return dsl.deserialize(Map.class, input, buffer);
3535
}
3636

3737
@Override
38-
public Map<String, Object> _readItems(String input) throws Exception {
39-
return _readItems(input.getBytes("UTF-8"));
38+
public Map<String, Object> _readMap(String input) throws Exception {
39+
return _readMap(input.getBytes("UTF-8"));
4040
}
4141
}

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,29 @@
1010

1111
import com.alibaba.fastjson.JSON;
1212
import com.alibaba.fastjson.parser.Feature;
13-
import com.cowtowncoder.jsonperf.dzone.DZoneReadTestBase;
13+
import com.cowtowncoder.jsonperf.dzone.DZoneMapReadTestBase;
1414

1515
@State(Scope.Thread)
1616
@OutputTimeUnit(TimeUnit.SECONDS)
17-
public class DZoneReadMapFastjson extends DZoneReadTestBase<Map<Object,Object>>
17+
public class DZoneReadMapFastjson extends DZoneMapReadTestBase
1818
{
19-
20-
public DZoneReadMapFastjson()
21-
{
22-
}
19+
public DZoneReadMapFastjson() { }
2320

2421
@SuppressWarnings("unchecked")
2522
@Override
26-
public Map<Object,Object> _readItems(byte[] input) throws Exception {
23+
public Map<Object,Object> _readMap(byte[] input) throws Exception {
2724
return (Map<Object,Object>) JSON.parse(input, Feature.DisableCircularReferenceDetect);
2825
}
2926

3027
@SuppressWarnings("unchecked")
3128
@Override
32-
public Map<Object,Object> _readItems(InputStream input) throws Exception {
29+
public Map<Object,Object> _readMap(InputStream input) throws Exception {
3330
return (Map<Object,Object>) JSON.parseObject(input, Map.class, Feature.DisableCircularReferenceDetect);
3431
}
3532

3633
@SuppressWarnings("unchecked")
3734
@Override
38-
public Map<Object,Object> _readItems(String input) throws Exception {
35+
public Map<Object,Object> _readMap(String input) throws Exception {
3936
return (Map<Object,Object>) JSON.parse(input, Feature.DisableCircularReferenceDetect);
4037
}
4138
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
import org.openjdk.jmh.annotations.Scope;
99
import org.openjdk.jmh.annotations.State;
1010

11-
import com.cowtowncoder.jsonperf.dzone.DZoneReadTestBase;
11+
import com.cowtowncoder.jsonperf.dzone.DZoneMapReadTestBase;
1212
import com.google.gson.Gson;
1313
import com.google.gson.GsonBuilder;
1414

1515
@State(Scope.Thread)
1616
@OutputTimeUnit(TimeUnit.SECONDS)
17-
public class DZoneReadMapGSON extends DZoneReadTestBase<Map<?,?>>
17+
public class DZoneReadMapGSON extends DZoneMapReadTestBase
1818
{
1919
protected final Gson gson;
2020

@@ -24,20 +24,20 @@ public DZoneReadMapGSON()
2424
}
2525

2626
@Override
27-
public Map<?,?> _readItems(byte[] input) throws Exception {
28-
return _readItems(new ByteArrayInputStream(input));
27+
public Map<?,?> _readMap(byte[] input) throws Exception {
28+
return _readMap(new ByteArrayInputStream(input));
2929
}
3030

3131
@Override
32-
public Map<?,?> _readItems(InputStream input) throws Exception {
32+
public Map<?,?> _readMap(InputStream input) throws Exception {
3333
InputStreamReader r = new InputStreamReader(input, "UTF-8");
3434
Map<?,?> value = gson.fromJson(r, Map.class);
3535
r.close();
3636
return value;
3737
}
3838

3939
@Override
40-
public Map<?,?> _readItems(String input) throws Exception {
40+
public Map<?,?> _readMap(String input) throws Exception {
4141
return gson.fromJson(input, Map.class);
4242
}
4343
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
import org.openjdk.jmh.annotations.Scope;
99
import org.openjdk.jmh.annotations.State;
1010

11-
import com.cowtowncoder.jsonperf.dzone.DZoneReadTestBase;
11+
import com.cowtowncoder.jsonperf.dzone.DZoneMapReadTestBase;
1212
import com.fasterxml.jackson.databind.ObjectMapper;
1313
import com.fasterxml.jackson.databind.ObjectReader;
1414

1515
@State(Scope.Thread)
1616
@OutputTimeUnit(TimeUnit.SECONDS)
17-
public class DZoneReadMapJackson extends DZoneReadTestBase<Map<Object,Object>>
17+
public class DZoneReadMapJackson extends DZoneMapReadTestBase
1818
{
1919
private final ObjectReader objectReader;
2020

@@ -24,17 +24,17 @@ public DZoneReadMapJackson()
2424
}
2525

2626
@Override
27-
public Map<Object,Object> _readItems(byte[] input) throws Exception {
27+
public Map<Object,Object> _readMap(byte[] input) throws Exception {
2828
return objectReader.readValue(input);
2929
}
3030

3131
@Override
32-
public Map<Object,Object> _readItems(InputStream input) throws Exception {
32+
public Map<Object,Object> _readMap(InputStream input) throws Exception {
3333
return objectReader.readValue(input);
3434
}
3535

3636
@Override
37-
public Map<Object,Object> _readItems(String input) throws Exception {
37+
public Map<Object,Object> _readMap(String input) throws Exception {
3838
return objectReader.readValue(input);
3939
}
4040
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import org.openjdk.jmh.annotations.Scope;
99
import org.openjdk.jmh.annotations.State;
1010

11-
import com.cowtowncoder.jsonperf.dzone.DZoneReadTestBase;
11+
import com.cowtowncoder.jsonperf.dzone.DZoneMapReadTestBase;
1212
import com.fasterxml.jackson.jr.ob.JSON;
1313

1414
@State(Scope.Thread)
1515
@OutputTimeUnit(TimeUnit.SECONDS)
16-
public class DZoneReadMapJacksonJr extends DZoneReadTestBase<Map<?,?>>
16+
public class DZoneReadMapJacksonJr extends DZoneMapReadTestBase
1717
{
1818
protected final JSON json;
1919

@@ -23,17 +23,17 @@ public DZoneReadMapJacksonJr()
2323
}
2424

2525
@Override
26-
public Map<?,?> _readItems(byte[] input) throws Exception {
26+
public Map<?,?> _readMap(byte[] input) throws Exception {
2727
return json.mapFrom(input);
2828
}
2929

3030
@Override
31-
public Map<?,?> _readItems(InputStream input) throws Exception {
31+
public Map<?,?> _readMap(InputStream input) throws Exception {
3232
return json.mapFrom(input);
3333
}
3434

3535
@Override
36-
public Map<?,?> _readItems(String input) throws Exception {
36+
public Map<?,?> _readMap(String input) throws Exception {
3737
return json.mapFrom(input);
3838
}
3939
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
import org.openjdk.jmh.annotations.Scope;
1212
import org.openjdk.jmh.annotations.State;
1313

14-
import com.cowtowncoder.jsonperf.dzone.DZoneReadTestBase;
14+
import com.cowtowncoder.jsonperf.dzone.DZoneMapReadTestBase;
1515

1616
@State(Scope.Thread)
1717
@OutputTimeUnit(TimeUnit.SECONDS)
18-
public class DZoneReadMapJohnzon extends DZoneReadTestBase<Map<?,?>>
18+
public class DZoneReadMapJohnzon extends DZoneMapReadTestBase
1919
{
2020
protected final Mapper mapper;
2121

@@ -25,19 +25,19 @@ public DZoneReadMapJohnzon()
2525
}
2626

2727
@Override
28-
public Map<?,?> _readItems(byte[] input) throws Exception {
29-
return _readItems(new ByteArrayInputStream(input));
28+
public Map<?,?> _readMap(byte[] input) throws Exception {
29+
return _readMap(new ByteArrayInputStream(input));
3030
}
3131

3232
@Override
33-
public Map<?,?> _readItems(InputStream input) throws Exception {
33+
public Map<?,?> _readMap(InputStream input) throws Exception {
3434
// force assign to ensure casting checks the type
3535
Map<?,?> value = mapper.readObject(input, Object.class);
3636
return value;
3737
}
3838

3939
@Override
40-
public Map<?,?> _readItems(String input) throws Exception {
40+
public Map<?,?> _readMap(String input) throws Exception {
4141
Map<?,?> value = mapper.readObject(input, Object.class);
4242
return value;
4343
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@
99
import org.openjdk.jmh.annotations.State;
1010

1111
import com.cedarsoftware.util.io.JsonReader;
12-
import com.cowtowncoder.jsonperf.dzone.DZoneReadTestBase;
12+
import com.cowtowncoder.jsonperf.dzone.DZoneMapReadTestBase;
1313

1414
@State(Scope.Thread)
1515
@OutputTimeUnit(TimeUnit.SECONDS)
16-
public class DZoneReadMapJsonIO extends DZoneReadTestBase<Map<?,?>>
16+
public class DZoneReadMapJsonIO extends DZoneMapReadTestBase
1717
{
1818
public DZoneReadMapJsonIO() { }
1919

2020
@Override
21-
public Map<?,?> _readItems(byte[] input) throws Exception {
22-
return _readItems(new ByteArrayInputStream(input));
21+
public Map<?,?> _readMap(byte[] input) throws Exception {
22+
return _readMap(new ByteArrayInputStream(input));
2323
}
2424

2525
@Override
26-
public Map<?,?> _readItems(InputStream input) throws Exception {
26+
public Map<?,?> _readMap(InputStream input) throws Exception {
2727
JsonReader r = new JsonReader(input);
2828
Map<?,?> value = (Map<?,?>) r.readObject();
2929
r.close();
3030
return value;
3131
}
3232

3333
@Override
34-
public Map<?,?> _readItems(String input) throws Exception {
34+
public Map<?,?> _readMap(String input) throws Exception {
3535
Map<?,?> value = (Map<?,?>) JsonReader.jsonToJava(input);
3636
return value;
3737
}

0 commit comments

Comments
 (0)