Skip to content

Comparison with FasterXML Jackson

Mitchell Hentges edited this page Jun 4, 2017 · 6 revisions

v1.3.4

Comparison with [email protected] (lower is better):

v1.3.0

Comparison (lower is better):

v1.2.0

Comparison (lower is better):

Explanation (v1.3.4 and above)

To get these results, I parsed the following JSON, where the values were randomly generated:

{\"a\":$boolean, \"uuid\": \"$uuid\", \"rand\": $floatPointNumber}
// e.g.: {"a": true, "uuid": "ce32337c-928d-469a-8c64-54aee99b5219", "rand": 0.2991049609188313}

I measured how long JsonParse and FasterXML took to read increasingly long lists of short JSON strings. Each time, I spun up a new JVM to ensure that there was no caching. The measurement logic can be seen in the fasterxml-comparison branch: see the main() method and bash script

When measuring, I include the time it takes to start the parsing implementation: JsonParse for this library, and ObjectMapper for FasterXML. In previous measurements (see below), I didn't include this startup cost, which was disingenuous

Explanation (v1.3.0 and before)

To get these results, I parsed the following JSON:

{\"a\":true, \"foo\": \"confirmed\", \"bar\": -3.642}

The full Java script is:

public static void main(String[] args) throws IOException {
    String toParse = "{\"a\":true, \"foo\": \"confirmed\", \"bar\": -3.642}";

    int iterations = Integer.parseInt(args[0]);
    ObjectMapper mapper = new ObjectMapper();
    JsonParse parse = new JsonParse();

    long start = System.currentTimeMillis();

    for (int i = 0; i < iterations; i++) {
        try {
            mapper.readValue(toParse, new TypeReference<Map<String, Object>>(){});
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    long fasterXml = System.currentTimeMillis() - start;
    start = System.currentTimeMillis();

    for (int i = 0; i < iterations; i++) {
        parse.map(toParse);
    }

    long jsonParse = System.currentTimeMillis() - start;
    System.out.printf("%d\t%d\t%d\n", iterations, fasterXml, jsonParse);
}

This program accepted a single argument - the number of times to parse the JSON. I used a small bash script to incrementally try more iterations:

#!/bin/bash

echo "Count   |FasterXML(ms)|JsonParse(ms)";

i="10"
while [ $i -le 5000000 ]
do
	java -jar target/json-parse-${VERSION}-jar-with-dependencies.jar $i
	let i*=4
done