-
Notifications
You must be signed in to change notification settings - Fork 6
Comparison with FasterXML Jackson
Comparison with [email protected]
(lower is better):
Comparison (lower is better):
Comparison (lower is better):
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
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