Skip to content

Commit

Permalink
use fastjson 2.0.51 & add fastjson_features case
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jun 1, 2024
1 parent bcbe996 commit 486b088
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The results here-below were computed on January the 30th, 2024 with the followin
| avaje-jsonb | 1.9 |
| boon | 0.34 |
| dsl-json | 1.10.0 |
| fastjson | 2.0.50 |
| fastjson | 2.0.51 |
| flexjson | 3.3 |
| genson | 1.6 |
| gson | 2.10.1 |
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ dependencies {
implementation group: 'com.dslplatform', name: 'dsl-json', version: "${dslJsonVersion}"
annotationProcessor group: 'com.dslplatform', name: 'dsl-json', version: "${dslJsonVersion}"
// FastJson
implementation group: 'com.alibaba.fastjson2', name: 'fastjson2', version: '2.0.50'
implementation group: 'com.alibaba.fastjson2', name: 'fastjson2-incubator-vector', version: '2.0.50'
implementation group: 'com.alibaba.fastjson2', name: 'fastjson2', version: '2.0.51'
implementation group: 'com.alibaba.fastjson2', name: 'fastjson2-incubator-vector', version: '2.0.51'
// FlexJson
implementation group: 'net.sf.flexjson', name: 'flexjson', version: '3.3'
// GENSON
Expand Down
2 changes: 1 addition & 1 deletion run
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
JAR=build/libs/app.jar
HEAP_SIZE=2g

[ -z ${JVM_OPTIONS} ] && JVM_OPTIONS="-server -Xms${HEAP_SIZE} -Xmx${HEAP_SIZE} --add-opens=java.base/java.time=ALL-UNNAMED --add-modules=jdk.incubator.vector -Dfastjson2.features=disableReferenceDetect,disableArrayMapping,disableJSONB,disableAutoType,disableSmartMatch"
[ -z ${JVM_OPTIONS} ] && JVM_OPTIONS="-server -Xms${HEAP_SIZE} -Xmx${HEAP_SIZE} --add-opens=java.base/java.time=ALL-UNNAMED --add-modules=jdk.incubator.vector"
[ -z ${SEED} ] && export SEED=${RANDOM}
[ -z ${SHADOW} ] && echo ./gradlew clean build shadowJar && ./gradlew clean build shadowJar

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 @@ -51,6 +51,10 @@ public Object fastjson() throws Exception {
return null;
}

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

public Object jsonio() throws Exception {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.fabienrenaud.jjb.databind;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.reader.ObjectReaderProvider;
import com.bluelinelabs.logansquare.LoganSquare;
import com.github.fabienrenaud.jjb.JsonBench;
import com.github.fabienrenaud.jjb.data.JsonSource;
Expand All @@ -15,6 +17,16 @@
* @author Fabien Renaud
*/
public class Deserialization extends JsonBench {
static final ObjectReaderProvider featuresProvider = new ObjectReaderProvider();
static final JSONReader.Context featuresContext;
static {
featuresProvider.setDisableArrayMapping(true);
featuresProvider.setDisableAutoType(true);
featuresProvider.setDisableJSONB(true);
featuresProvider.setDisableReferenceDetect(true);
featuresProvider.setDisableSmartMatch(true);
featuresContext = new JSONReader.Context(featuresProvider);
}

public JsonSource JSON_SOURCE() {
return CLI_JSON_SOURCE;
Expand Down Expand Up @@ -62,6 +74,12 @@ public Object fastjson() {
return JSON.parseObject(JSON_SOURCE().nextByteArray(), JSON_SOURCE().pojoType());
}

@Benchmark
@Override
public Object fastjson_features() {
return JSON.parseObject(JSON_SOURCE().nextByteArray(), JSON_SOURCE().pojoType(), featuresContext);
}

@Benchmark
@Override
public Object flexjson() throws JsonSyntaxException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.github.fabienrenaud.jjb.databind;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONFactory;
import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.writer.ObjectWriterProvider;
import com.bluelinelabs.logansquare.LoganSquare;
import com.github.fabienrenaud.jjb.JsonBench;
import com.github.fabienrenaud.jjb.JsonUtils;
Expand All @@ -13,6 +16,15 @@
import java.io.ByteArrayOutputStream;

public class Serialization extends JsonBench {
static final ObjectWriterProvider featuresProvider = new ObjectWriterProvider();
static final JSONWriter.Context featuresContext;
static {
featuresProvider.setDisableAutoType(true);
featuresProvider.setDisableArrayMapping(true);
featuresProvider.setDisableJSONB(true);
featuresProvider.setDisableReferenceDetect(true);
featuresContext = JSONFactory.createWriteContext(featuresProvider);
}

public JsonSource JSON_SOURCE() {
return CLI_JSON_SOURCE;
Expand Down Expand Up @@ -74,6 +86,14 @@ public Object fastjson() throws Exception {
return baos;
}

@Benchmark
@Override
public Object fastjson_features() throws Exception {
ByteArrayOutputStream baos = JsonUtils.byteArrayOutputStream();
JSON.writeTo(baos, JSON_SOURCE().nextPojo(), featuresContext);
return baos;
}

@Benchmark
@Override
public Object flexjson() {
Expand Down

0 comments on commit 486b088

Please sign in to comment.