Created
October 21, 2015 08:27
-
-
Save mvitz/88870a52aafa3cbc631e to your computer and use it in GitHub Desktop.
Adam Bien JSON Parser Benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mvn clean package && java -jar target/jmh-abien-json-1.0-SNAPSHOT.jar -f 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.innoq; | |
import java.util.Map; | |
import javax.script.ScriptEngine; | |
import javax.script.ScriptEngineManager; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import org.openjdk.jmh.annotations.Benchmark; | |
import org.openjdk.jmh.annotations.Scope; | |
import org.openjdk.jmh.annotations.Setup; | |
import org.openjdk.jmh.annotations.State; | |
@State(Scope.Benchmark) | |
public class MyBenchmark { | |
private ScriptEngine engine; | |
private ObjectMapper mapper; | |
private String json; | |
@Setup | |
public void setUp() throws Exception { | |
engine = new ScriptEngineManager().getEngineByName("javascript"); | |
mapper = new ObjectMapper(); | |
json = "{ \"foo\": \"bar\", \"bar\": 1 }"; | |
} | |
@Benchmark | |
public Object nashorn() throws Exception { | |
Map<String, Object> map = (Map<String, Object>) engine.eval("Java.asJSONCompatible(" + json + ")"); | |
return map.get("foo"); | |
} | |
@Benchmark | |
public Object jackson() throws Exception { | |
Map<String, Object> map = mapper.readValue(json, Map.class); | |
return map.get("foo"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.innoq</groupId> | |
<artifactId>jmh-abien-json</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<properties> | |
<encoding>UTF-8</encoding> | |
<maven.compiler.source>1.8</maven.compiler.source> | |
<maven.compiler.target>1.8</maven.compiler.target> | |
<jackson.version>2.6.3</jackson.version> | |
<jmh.version>1.11.1</jmh.version> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>com.fasterxml.jackson.core</groupId> | |
<artifactId>jackson-databind</artifactId> | |
<version>${jackson.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.openjdk.jmh</groupId> | |
<artifactId>jmh-core</artifactId> | |
<version>${jmh.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.openjdk.jmh</groupId> | |
<artifactId>jmh-generator-annprocess</artifactId> | |
<version>${jmh.version}</version> | |
<scope>provided</scope> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-shade-plugin</artifactId> | |
<version>2.2</version> | |
<executions> | |
<execution> | |
<phase>package</phase> | |
<goals> | |
<goal>shade</goal> | |
</goals> | |
<configuration> | |
<transformers> | |
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | |
<mainClass>org.openjdk.jmh.Main</mainClass> | |
</transformer> | |
</transformers> | |
<filters> | |
<filter> | |
<artifact>*:*</artifact> | |
<excludes> | |
<exclude>META-INF/*.SF</exclude> | |
<exclude>META-INF/*.DSA</exclude> | |
<exclude>META-INF/*.RSA</exclude> | |
</excludes> | |
</filter> | |
</filters> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
Interesting.
What about memory consumption? How does that compare?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My results: