Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ cc_binary(
"@cJSON",
"@yyjson",
"@simdjson",
"@jsoncpp//:jsoncpp",
],
copts = common_copts + ['-DNDEBUG', '-std=c++17'],
linkopts = ['-lstdc++fs'],
Expand Down
6 changes: 6 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ new_git_repository(
remote = "https://github.com/ibireme/yyjson.git",
)

git_repository(
name = "jsoncpp",
branch = "master",
remote = "https://github.com/open-source-parsers/jsoncpp",
)

git_repository(
name = "gflags",
branch = "master",
Expand Down
4 changes: 3 additions & 1 deletion benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(COMPILE_FLAGS -O3 -DNDEBUG -g -mavx2 -mpclmul -mbmi -mlzcnt)

include("${PROJECT_SOURCE_DIR}/cmake/external.cmake")

unset(CMAKE_RUNTIME_OUTPUT_DIRECTORY CACHE)
add_executable(bench "${BENCH_SRC}")

set(EP_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/)
Expand All @@ -23,14 +24,15 @@ ExternalProject_Add(
add_dependencies(bench google_benchmark)

target_compile_features(bench PRIVATE cxx_std_17)
target_link_libraries(bench simdjson yyjson cjson benchmark benchmark_main pthread stdc++fs)
target_link_libraries(bench simdjson yyjson cjson jsoncpp_lib benchmark benchmark_main pthread stdc++fs)
target_include_directories(bench
PRIVATE ${rapidjson_SOURCE_DIR}/include
PRIVATE ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}
PRIVATE ${EP_PREFIX}/src/google_benchmark/include/
PRIVATE ${cjson_SOURCE_DIR}/
PRIVATE ${yyjson_SOURCE_DIR}/src/
PRIVATE ${simdjson_SOURCE_DIR}/singleheader/
PRIVATE ${jsoncpp_SOURCE_DIR}/include/
)
target_link_directories(bench
PRIVATE ${EP_PREFIX}/src/google_benchmark-build/src
Expand Down
82 changes: 82 additions & 0 deletions benchmark/jsoncpp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2022 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef _JsonCpp_HPP_
#define _JsonCpp_HPP_
#include "json.h"
#include "json/json.h"

class JsonCppStringResult : public StringResult<JsonCppStringResult> {
public:
std::string_view str_impl() const { return data.c_str(); }
std::string data;
};

class JsonCppParseResult
: public ParseResult<JsonCppParseResult, JsonCppStringResult> {
public:
Json::Value document;

JsonCppParseResult(std::string_view json) { (void)json; }
~JsonCppParseResult() {}

bool contains_impl(std::string_view key) const {
return document.isMember(key.data(), key.data() + key.size());
}

bool stringfy_impl(JsonCppStringResult &sr) const {
Json::StreamWriterBuilder writer_builder;
std::unique_ptr<Json::StreamWriter> stream_writer(
writer_builder.newStreamWriter());
std::ostringstream oss;
int res = stream_writer->write(document, &oss);
sr.data = oss.str();
return (res == 0 && oss.good());
}

bool prettify_impl(JsonCppStringResult &sr) const {
(void)sr;
return false;
}

bool stat_impl(DocStat &stat) const {
(void)stat;
return true;
}

bool find_impl(DocStat &stat) const {
(void)stat;
return true;
}

private:
};

class JsonCpp : public JsonBase<JsonCpp, JsonCppParseResult> {
public:
bool parse_impl(std::string_view json, JsonCppParseResult &pr) const {
Json::CharReaderBuilder reader_builder;
std::unique_ptr<Json::CharReader> char_reader(
reader_builder.newCharReader());
if (!char_reader->parse(json.data(), json.data() + json.size(),
&pr.document, nullptr)) {
return false;
}
return true;
}
};

#endif
2 changes: 2 additions & 0 deletions benchmark/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <string_view>

#include "cjson.hpp"
#include "jsoncpp.hpp"
#include "ondemand.hpp"
#include "rapidjson.hpp"
#include "simdjson.hpp"
Expand Down Expand Up @@ -225,6 +226,7 @@ int main(int argc, char **argv) {
ADD_JSON_BMK(Rapidjson, METHOD); \
ADD_JSON_BMK(YYjson, METHOD); \
ADD_JSON_BMK(SIMDjson, METHOD); \
ADD_JSON_BMK(JsonCpp, METHOD); \
} \
} while (0)

Expand Down
6 changes: 6 additions & 0 deletions cmake/external.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ FetchContent_Declare(
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(yyjson)

FetchContent_Declare(
jsoncpp
GIT_REPOSITORY https://github.com/open-source-parsers/jsoncpp.git
GIT_TAG master
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(jsoncpp)