I've been testing the performance of Simdjson recently. The basic test is similar to default test, using twitter.json, as below:
@BenchmarkpublicintrecordSimdjson() {
Set<String> defaultUsers = newHashSet<>();
TwitterRecordtwitter = simdJsonParser.parse(buffer, buffer.length, TwitterRecord.class);
for (StatusRecordstatus : twitter.statuses()) {
UserRecorduser = status.user();
if (user.default_profile()) {
defaultUsers.add(user.screen_name());
}
}
returndefaultUsers.size();
}
@BenchmarkpublicintJsonValueSimdjson() {
JsonValuesimdJsonValue = simdJsonParser.parse(buffer, buffer.length);
Set<String> defaultUsers = newHashSet<>();
Iterator<JsonValue> tweets = simdJsonValue.get("statuses").arrayIterator();
while (tweets.hasNext()) {
JsonValuetweet = tweets.next();
JsonValueuser = tweet.get("user");
if (user.get("default_profile").asBoolean()) {
defaultUsers.add(user.get("screen_name").asString());
}
}
returndefaultUsers.size();
}
@BenchmarkpublicintrecordJackson() throwsIOException {
Set<String> defaultUsers = newHashSet<>();
TwitterRecordtwitter = objectMapper.readValue(buffer, TwitterRecord.class);
for (StatusRecordstatus : twitter.statuses()) {
UserRecorduser = status.user();
if (user.default_profile()) {
defaultUsers.add(user.screen_name());
}
}
returndefaultUsers.size();
}
recordUserRecord(booleandefault_profile, Stringscreen_name) {
}
recordStatusRecord(UserRecorduser) {
}
recordTwitterRecord(List<StatusRecord> statuses) {
}What's different is I shrunk the size of statuses, default is 101, I tested 101, 51, and 1 respectively, the result is below:
size 101:

size 51:

size 1:

What's more, I changed the depth of test, the default is 3 and I changed it to 2, as below:
@BenchmarkpublicintrecordSimdjson() {
Set<Object> defaultUsers = newHashSet<>();
TwitterRecordtwitter = simdJsonParser.parse(buffer, buffer.length, TwitterRecord.class);
for (StatusRecordstatus : twitter.statuses()) {
longid = status.id();
Stringtext = status.text();
defaultUsers.add(id);
defaultUsers.add(text);
}
returndefaultUsers.size();
}
@BenchmarkpublicintJsonValueSimdjson() {
JsonValuesimdJsonValue = simdJsonParser.parse(buffer, buffer.length);
Set<Object> defaultUsers = newHashSet<>();
Iterator<JsonValue> tweets = simdJsonValue.get("statuses").arrayIterator();
while (tweets.hasNext()) {
JsonValuetweet = tweets.next();
JsonValueid = tweet.get("id");
JsonValuetext = tweet.get("text");
defaultUsers.add(id.asLong());
defaultUsers.add(text.asString());
}
returndefaultUsers.size();
}
@BenchmarkpublicintrecordJackson() throwsIOException {
Set<Object> defaultUsers = newHashSet<>();
TwitterRecordtwitter = objectMapper.readValue(buffer, TwitterRecord.class);
for (StatusRecordstatus : twitter.statuses()) {
longid = status.id();
Stringtext = status.text();
defaultUsers.add(id);
defaultUsers.add(text);
}
returndefaultUsers.size();
}
recordStatusRecord(longid, Stringtext) {
}
recordTwitterRecord(List<StatusRecord> statuses) {
}The results are:
size 101:

size 51:

size 1:

Here are my questions:
- The performance of Simdjson is not always faster than jackson? The shorter the JSON, the worse of Simdjson? If my JSON is short, I'd better not use simdjson?
- DOM Parser vs Schema-Based Parser, the performance also depends on size of JSON? My first thought is Schema-Based is faster.
I've been testing the performance of Simdjson recently. The basic test is similar to default test, using twitter.json, as below:
What's different is I shrunk the size of statuses, default is 101, I tested 101, 51, and 1 respectively, the result is below:

size 101:
size 51:

size 1:

What's more, I changed the depth of test, the default is 3 and I changed it to 2, as below:
The results are:

size 101:
size 51:

size 1:

Here are my questions: