Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jmh.version>1.25.2</jmh.version>
<jmh.version>1.37</jmh.version>
<uberjar.name>benchmarks</uberjar.name>
</properties>

Expand Down Expand Up @@ -58,15 +58,38 @@
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-afterburner</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-blackbird</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<version>2.13.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.dslplatform</groupId>
<artifactId>dsl-json</artifactId>
<version>2.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand All @@ -84,6 +107,12 @@
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/BenchmarkList</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/CompilerHints</resource>
</transformer>
</transformers>
<filters>
<filter>
Expand Down
113 changes: 113 additions & 0 deletions benchmark/src/main/java/org/sample/MyBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@

package org.sample;

import com.dslplatform.json.DslJson;
import com.dslplatform.json.runtime.Settings;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
import com.fasterxml.jackson.module.blackbird.BlackbirdModule;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
Expand All @@ -50,6 +54,7 @@
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;
import org.sample.jackson.Person2Deserializer;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -180,6 +185,24 @@ public void setup() {
}
}

@State(Scope.Benchmark)
public static class BlackbirdWriter {
public com.fasterxml.jackson.databind.ObjectWriter objectWriter;
public Person2 person;

@Setup(Level.Trial)
public void setup() {
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, false);
mapper.registerModule(new BlackbirdModule());
objectWriter = mapper.writerFor(Person2.class);
try {
person = mapper.readerFor(Person2.class).readValue(new StringReader(json));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

@State(Scope.Benchmark)
public static class SimpleQsonWriter {
Expand Down Expand Up @@ -290,6 +313,62 @@ public void setup() {
}
}

@State(Scope.Benchmark)
public static class BlackbirdParser {
public ObjectReader reader;
public byte[] jsonBytes;

@Setup(Level.Trial)
public void setup() {
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, false);
mapper.registerModule(new BlackbirdModule());
reader = mapper.readerFor(Person2.class);
try {
jsonBytes = json.getBytes("UTF-8");
} catch (Exception e) {
throw new RuntimeException();
}
}
}

@State(Scope.Benchmark)
public static class JacksonCustomParser {
public ObjectReader reader;
public byte[] jsonBytes;

@Setup(Level.Trial)
public void setup() {
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, false);
SimpleModule module = new SimpleModule();
module.addDeserializer(Person2.class, new Person2Deserializer());
mapper.registerModule(module);
reader = mapper.readerFor(Person2.class);
try {
jsonBytes = json.getBytes("UTF-8");
} catch (Exception e) {
throw new RuntimeException();
}
}
}

@State(Scope.Benchmark)
public static class DslJsonParser {
public DslJson<Person2> reader;
public byte[] jsonBytes;

@Setup(Level.Trial)
public void setup() {
reader = new DslJson<>(Settings.basicSetup());
try {
jsonBytes = json.getBytes("UTF-8");
} catch (Exception e) {
throw new RuntimeException();
}
}
}

@State(Scope.Benchmark)
public static class GsonParser {
public Gson gson;
Expand Down Expand Up @@ -349,7 +428,32 @@ public Object testParserAfterburner(AfterburnerParser a) {
}
}

@Benchmark
public Object testParserBlackbird(BlackbirdParser a) {
try {
return a.reader.readValue(a.jsonBytes);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Benchmark
public Object testParserJacksonCustom(JacksonCustomParser a) {
try {
return a.reader.readValue(a.jsonBytes);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Benchmark
public Object testParserDslJson(DslJsonParser a) {
try {
return a.reader.deserialize(Person2.class, new ByteArrayInputStream(a.jsonBytes));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Benchmark
public Object testWriterQson(QsonWriter q) {
Expand All @@ -373,4 +477,13 @@ public Object testWriterAfterburner(AfterburnerWriter q) {
throw new RuntimeException(e);
}
}

@Benchmark
public Object testWriterBlackbird(BlackbirdWriter q) {
try {
return q.objectWriter.writeValueAsBytes(q.person);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Loading