Skip to content

Commit

Permalink
jodd
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienrenaud committed Nov 11, 2016
1 parent e2fd0e1 commit 288a4e6
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 3 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ dependencies {
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
// nanojson
compile group: 'com.grack', name: 'nanojson', version: '1.2'
// jodd
compile group: 'org.jodd', name: 'jodd-json', version: '3.8.0'

// Test
testCompile group: 'junit', name: 'junit', version: '4.12'

// IMPORANT: Leave JMH at the end!
// IMPORTANT: Leave JMH at the end!
// JMH
compile group: 'org.openjdk.jmh', name: 'jmh-core', version: '1.15'
apt group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version: '1.15'
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/github/fabienrenaud/jjb/JsonBench.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@ public Object nanojson() throws Exception {
return null;
}

public Object jodd() throws Exception {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,10 @@ public Object dsljson() throws Exception {
public Object logansquare() throws Exception {
return LoganSquare.parse(JSON_SOURCE.nextInputStream(), JSON_SOURCE.pojoType());
}

@Benchmark
@Override
public Object jodd() throws Exception {
return JSON_SOURCE.provider().joddDeser().parse(JSON_SOURCE.nextString(), JSON_SOURCE.pojoType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,10 @@ public Object logansquare() throws Exception {
LoganSquare.serialize(JSON_SOURCE.nextPojo(), baos);
return baos;
}

@Benchmark
@Override
public Object jodd() throws Exception {
return JSON_SOURCE.provider().joddSer().serialize(JSON_SOURCE.nextPojo());
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/github/fabienrenaud/jjb/model/Users.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
*/
@JsonObject
@CompiledJson
@jodd.json.meta.JSON
public class Users {

@JsonField
@jodd.json.meta.JSON
public List<User> users;

@Override
Expand Down Expand Up @@ -79,9 +81,11 @@ public static final class User {
public double longitude;
@JsonField
@JsonAttribute(nullable = false)
@jodd.json.meta.JSON
public List<String> tags;
@JsonField
@JsonAttribute(nullable = false)
@jodd.json.meta.JSON
public List<Friend> friends;
@JsonField
public String greeting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ public interface JsonProvider<T> {
Map<String, Object> jsonioStreamOptions();

DslJson<T> dsljson();

jodd.json.JsonParser joddDeser();

jodd.json.JsonSerializer joddSer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,28 @@ public Map<String, Object> jsonioStreamOptions() {
public DslJson<Users> dsljson() {
return dsljson;
}

@Override
public jodd.json.JsonParser joddDeser() {
return JODD_DESER.get();
}

@Override
public jodd.json.JsonSerializer joddSer() {
return JODD_SER.get();
}

private static final ThreadLocal<jodd.json.JsonParser> JODD_DESER = new ThreadLocal<jodd.json.JsonParser>() {
@Override
protected jodd.json.JsonParser initialValue() {
return new jodd.json.JsonParser();
}
};

private static final ThreadLocal<jodd.json.JsonSerializer> JODD_SER = new ThreadLocal<jodd.json.JsonSerializer>() {
@Override
protected jodd.json.JsonSerializer initialValue() {
return new jodd.json.JsonSerializer();
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public enum BenchSupport {
new Libapi(Library.DSLJSON, Api.DATABIND),
new Libapi(Library.LOGANSQUARE, Api.DATABIND),
new Libapi(Library.JSONSIMPLE, Api.STREAM),
new Libapi(Library.NANOJSON, Api.STREAM)
new Libapi(Library.NANOJSON, Api.STREAM),
new Libapi(Library.JODD, Api.DATABIND)
);

private final List<Libapi> libapis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public enum Library {
DSLJSON,
LOGANSQUARE,
JSONSIMPLE,
NANOJSON;
NANOJSON,
JODD;

public static Set<Library> fromCsv(String str) {
if (str == null || str.trim().isEmpty()) {
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/com/github/fabienrenaud/jjb/JsonBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,11 @@ public void nanojson() throws Exception {
test(Library.NANOJSON, BENCH.nanojson());
}
}

@Test
public void jodd() throws Exception {
for (int i = 0; i < ITERATIONS; i++) {
test(Library.JODD, BENCH.jodd());
}
}
}

0 comments on commit 288a4e6

Please sign in to comment.