Skip to content

nlohmann VS JsonCpp by C++17 #1633

Description

@zhongcy

Hi, I test nlohmann and JsonCpp in C++17.

Env:
CentOS 7.5 64Bit
4vCPU, 8GB Mem, 100GB Disk

nlohmann Release 3.6.1
jsoncpp Release 0.10.5

[root@zhongcy home]$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-7/root/usr --mandir=/opt/rh/devtoolset-7/root/usr/share/man --infodir=/opt/rh/devtoolset-7/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --with-default-libstdcxx-abi=gcc4-compatible --with-isl=/builddir/build/BUILD/gcc-7.3.1-20180303/obj-x86_64-redhat-linux/isl-install --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC)

Codes and result like:

`
#include "nlohmann/json.hpp"
#include <json/writer.h>

std::string sStr =
R"json(
{ "name": "myserver-consumer#consumer-1", "client_id": "myserver-consumer", "type": "consumer", "ts":1916750966985, "time":1560232284, "replyq":0, "msg_cnt":0, "msg_size":0, "msg_max":0, "msg_size_max":0, "simple_cnt":0, "metadata_cache_cnt":1, "brokers":{ "127.0.0.1:9092/1": { "name":"127.0.0.1:9092/1", "nodeid":1, "nodename":"127.0.0.1:9092", "source":"learned", "state":"INIT", "stateage":1989943, "outbuf_cnt":0, "outbuf_msg_cnt":0, "waitresp_cnt":0, "waitresp_msg_cnt":0, "tx":0, "txbytes":0, "txerrs":0, "txretries":0, "req_timeouts":0, "rx":0, "rxbytes":0, "rxerrs":0, "rxcorriderrs":0, "rxpartial":0, "zbuf_grow":0, "buf_grow":0, "wakeups":0, "connects":0, "disconnects":0, "int_latency": { "min":0, "max":0, "avg":0, "sum":0, "stddev": 0, "p50": 0, "p75": 0, "p90": 0, "p95": 0, "p99": 0, "p99_99": 0, "outofrange": 0, "hdrsize": 11376, "cnt":0 }, "outbuf_latency":{ "min":0, "max":0, "avg":0, "sum":0, "stddev": 0, "p50": 0, "p75": 0, "p90": 0, "p95": 0, "p99": 0, "p99_99": 0, "outofrange": 0, "hdrsize": 11376, "cnt":0 }, "rtt": { "min":0, "max":0, "avg":0, "sum":0, "stddev": 0, "p50": 0, "p75": 0, "p90": 0, "p95": 0, "p99": 0, "p99_99": 0, "outofrange": 0, "hdrsize": 13424, "cnt":0 }, "throttle": { "min":0, "max":0, "avg":0, "sum":0, "stddev": 0, "p50": 0, "p75": 0, "p90": 0, "p95": 0, "p99": 0, "p99_99": 0,"outofrange": 0, "hdrsize": 17520, "cnt":0 }, "req": { "Fetch": 0, "Offset": 0, "Metadata": 0, "OffsetCommit": 0, "OffsetFetch": 0, "GroupCoordinator": 0, "JoinGroup": 0, "Heartbeat": 0, "LeaveGroup": 0, "SyncGroup": 0, "SaslHandshake": 0, "ApiVersion": 0 }, "toppars":{ } } , "127.0.0.1:9092/bootstrap": { "name":"127.0.0.1:9092/bootstrap", "nodeid":-1, "nodename":"127.0.0.1:9092", "source":"configured", "state":"UP", "stateage":1993368, "outbuf_cnt":0, "outbuf_msg_cnt":0, "waitresp_cnt":0, "waitresp_msg_cnt":0, "tx":5, "txbytes":242, "txerrs":0, "txretries":0, "req_timeouts":0, "rx":5, "rxbytes":577, "rxerrs":0, "rxcorriderrs":0, "rxpartial":0, "zbuf_grow":0, "buf_grow":0, "wakeups":15, "connects":1, "disconnects":0, "int_latency": { "min":0, "max":0, "avg":0, "sum":0, "stddev": 0, "p50": 0, "p75": 0, "p90": 0, "p95": 0, "p99": 0, "p99_99": 0, "outofrange": 0, "hdrsize": 11376, "cnt":0 }, "outbuf_latency": { "min":32, "max":342, "avg":144, "sum":433, "stddev": 140, "p50": 59, "p75": 59, "p90": 343, "p95": 343, "p99":343, "p99_99": 343, "outofrange": 0, "hdrsize": 11376, "cnt":3 }, "rtt": { "min":3173, "max":4331, "avg":3690, "sum":11070, "stddev": 482, "p50": 3567, "p75": 3567, "p90": 4351, "p95": 4351, "p99": 4351, "p99_99": 4351, "outofrange": 0, "hdrsize": 13424, "cnt":3 }, "throttle": { "min":0, "max":0, "avg":0, "sum":0, "stddev": 0, "p50": 0, "p75": 0, "p90": 0, "p95": 0, "p99": 0, "p99_99": 0, "outofrange": 0, "hdrsize": 17520, "cnt":0 }, "req": { "Fetch": 0, "Offset": 0, "Metadata": 2, "OffsetCommit": 0, "OffsetFetch": 0, "GroupCoordinator": 2, "JoinGroup": 0, "Heartbeat": 0, "LeaveGroup": 0, "SyncGroup": 0, "SaslHandshake": 0, "ApiVersion": 1 }, "toppars":{ } } , "GroupCoordinator": { "name":"GroupCoordinator", "nodeid":-1, "nodename":"127.0.0.1:9092", "source":"logical", "state":"UP", "stateage":990212, "outbuf_cnt":0, "outbuf_msg_cnt":0, "waitresp_cnt":0, "waitresp_msg_cnt":0, "tx":2, "txbytes":80, "txerrs":0, "txretries":0, "req_timeouts":0, "rx":2, "rxbytes":353, "rxerrs":0, "rxcorriderrs":0, "rxpartial":0, "zbuf_grow":0, "buf_grow":0, "wakeups":6, "connects":1, "disconnects":0, "int_latency": { "min":0, "max":0, "avg":0, "sum":0, "stddev": 0, "p50": 0, "p75": 0, "p90": 0, "p95": 0, "p99": 0, "p99_99": 0, "outofrange": 0, "hdrsize": 11376, "cnt":0 }, "outbuf_latency": { "min":40, "max":49, "avg":44, "sum":89, "stddev": 4, "p50": 40, "p75": 49, "p90": 49, "p95": 49, "p99": 49, "p99_99": 49, "outofrange": 0, "hdrsize": 11376, "cnt":2 }, "rtt": { "min":2757, "max":2835, "avg":2796, "sum":5592, "stddev": 40, "p50": 2767, "p75": 2847, "p90": 2847, "p95": 2847, "p99": 2847, "p99_99": 2847, "outofrange": 0, "hdrsize": 13424, "cnt":2 }, "throttle": { "min":0, "max":0, "avg":0, "sum":0, "stddev": 0, "p50": 0, "p75": 0, "p90": 0, "p95": 0, "p99": 0, "p99_99": 0, "outofrange": 0, "hdrsize": 17520, "cnt":0 }, "req": { "Fetch": 0, "Offset": 0, "Metadata": 1, "OffsetCommit": 0, "OffsetFetch": 0, "GroupCoordinator": 0, "JoinGroup": 0, "Heartbeat": 0, "LeaveGroup": 0, "SyncGroup": 0, "SaslHandshake": 0, "ApiVersion": 1 }, "toppars":{ } } }, "topics":{ } , "cgrp": { "state": "up", "stateage": 987, "join_state": "init", "rebalance_age": 983, "rebalance_cnt": 2, "rebalance_reason": "group rejoin", "assignment_size": 0 }, "tx":7, "tx_bytes":322, "rx":7, "rx_bytes":930, "txmsgs":0, "txmsg_bytes":0, "rxmsgs":0, "rxmsg_bytes":0}
)json";

uint64_t timebegin = now();
if (false)
{
nlohmann::json sRoot = nlohmann::json::parse(sStr);
} else {
//JsonCpp
Json::Reader sReader;
Json::Value sRoot;
bool sRet = sReader.parse(sStr, sRoot);
}
uint64_t timeused = now() - timebegin;
LOG_DEBUG("timeused:%ld", timeused);
`

Use default: -O0

resule:
JsonCpp: timeused:513
nlohmann: timeused:5345

Why nlohmann::parse is such slower than JsonCpp::parse ?
Is nlohmann not high performance by C++17 ?
@nlohmann @theodelrieu

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions