Add PartialTweets<Yyjson> benchmark

This commit is contained in:
John Keiser 2021-01-01 21:15:03 -08:00
parent 0314889c6d
commit 9af41dd988
4 changed files with 92 additions and 11 deletions

View File

@ -48,6 +48,9 @@ if (TARGET benchmark::benchmark)
add_executable(bench_parse_call bench_parse_call.cpp)
add_executable(bench_dom_api bench_dom_api.cpp)
add_executable(bench_ondemand bench_ondemand.cpp)
if (TARGET yyjson)
target_link_libraries(bench_ondemand PRIVATE yyjson)
endif ()
endif()
include(checkperf.cmake)

View File

@ -1,30 +1,36 @@
#include "simdjson.h"
#include <iostream>
#include <sstream>
#include <random>
#include <vector>
SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
#ifdef SIMDJSON_COMPETITION_YYJSON
#include "yyjson.h"
#endif
#include <benchmark/benchmark.h>
SIMDJSON_POP_DISABLE_WARNINGS
// simdjson ondemand
#include "partial_tweets/ondemand.h"
// #include "partial_tweets/iter.h"
#include "partial_tweets/dom.h"
#include "largerandom/ondemand.h"
#include "largerandom/ondemand_unordered.h"
// #include "largerandom/iter.h"
#include "largerandom/dom.h"
#include "kostya/ondemand.h"
// #include "kostya/iter.h"
#include "kostya/dom.h"
#include "distinctuserid/ondemand.h"
#include "distinctuserid/dom.h"
#include "find_tweet/ondemand.h"
// simdjson dom
#include "partial_tweets/dom.h"
#include "largerandom/dom.h"
#include "kostya/dom.h"
#include "distinctuserid/dom.h"
#include "find_tweet/dom.h"
// // yyjson
#ifdef SIMDJSON_COMPETITION_YYJSON
#include "partial_tweets/yyjson.h"
#endif
BENCHMARK_MAIN();

View File

@ -0,0 +1,59 @@
#pragma once
#include "partial_tweets.h"
namespace partial_tweets {
class Yyjson {
public:
simdjson_really_inline const std::vector<tweet> &Result() { return tweets; }
simdjson_really_inline size_t ItemCount() { return tweets.size(); }
private:
std::vector<tweet> tweets{};
simdjson_really_inline std::string_view get_string_view(yyjson_val *obj, std::string_view key) {
auto val = yyjson_obj_getn(obj, key.data(), key.length());
return { yyjson_get_str(val), yyjson_get_len(val) };
}
simdjson_really_inline uint64_t get_uint64(yyjson_val *obj, std::string_view key) {
auto val = yyjson_obj_getn(obj, key.data(), key.length());
return yyjson_get_uint(val);
}
simdjson_really_inline partial_tweets::twitter_user get_user(yyjson_val *obj, std::string_view key) {
auto user = yyjson_obj_getn(obj, key.data(), key.length());
return { get_uint64(user, "id"), get_string_view(user, "screen_name") };
}
public:
simdjson_really_inline bool Run(const padded_string &json) {
tweets.clear();
// Walk the document, parsing the tweets as we go
yyjson_doc *doc = yyjson_read(json.data(), json.size(), 0);
if (!doc) { return false; }
yyjson_val *root = yyjson_doc_get_root(doc);
yyjson_val *statuses = yyjson_obj_get(root, "statuses");
size_t tweet_idx, tweets_max;
yyjson_val *tweet;
yyjson_arr_foreach(statuses, tweet_idx, tweets_max, tweet) {
// TODO these can't actually handle errors
tweets.emplace_back(partial_tweets::tweet{
get_string_view(tweet, "created_at"),
get_uint64 (tweet, "id"),
get_string_view(tweet, "text"),
get_uint64 (tweet, "in_reply_to_status_id"),
get_user (tweet, "user"),
get_uint64 (tweet, "retweet_count"),
get_uint64 (tweet, "favorite_count")
});
}
return true;
}
};
BENCHMARK_TEMPLATE(PartialTweets, Yyjson);
} // namespace partial_tweets

View File

@ -38,11 +38,13 @@ int main() {}
target_compile_definitions(boostjson PUBLIC BOOST_JSON_STANDALONE)
target_include_directories(boostjson SYSTEM PUBLIC
"${boostjson_SOURCE_DIR}/include")
target_compile_definitions(boostjson INTERFACE SIMDJSON_COMPETITION_BOOSTJSON)
endif()
import_dependency(cjson DaveGamble/cJSON c69134d)
add_library(cjson STATIC "${cjson_SOURCE_DIR}/cJSON.c")
target_include_directories(cjson SYSTEM PUBLIC "${cjson_SOURCE_DIR}")
target_compile_definitions(cjson INTERFACE SIMDJSON_COMPETITION_CJSON)
import_dependency(fastjson mikeando/fastjson 485f994)
add_library(fastjson STATIC
@ -51,14 +53,17 @@ int main() {}
"${fastjson_SOURCE_DIR}/src/fastjson_dom.cpp")
target_include_directories(fastjson SYSTEM PUBLIC
"${fastjson_SOURCE_DIR}/include")
target_compile_definitions(fastjson INTERFACE SIMDJSON_COMPETITION_FASTJSON)
import_dependency(gason vivkin/gason 7aee524)
add_library(gason STATIC "${gason_SOURCE_DIR}/src/gason.cpp")
target_include_directories(gason SYSTEM PUBLIC "${gason_SOURCE_DIR}/src")
target_compile_definitions(gason INTERFACE SIMDJSON_COMPETITION_GASON)
import_dependency(jsmn zserge/jsmn 18e9fe4)
add_library(jsmn STATIC "${jsmn_SOURCE_DIR}/jsmn.c")
target_include_directories(jsmn SYSTEM PUBLIC "${jsmn_SOURCE_DIR}")
target_compile_definitions(jsmn INTERFACE SIMDJSON_COMPETITION_JSMN)
message(STATUS "Importing json (nlohmann/json@v3.9.1)")
set(nlohmann_json_SOURCE_DIR "${dep_root}/json")
@ -69,26 +74,31 @@ int main() {}
endif()
add_library(nlohmann_json INTERFACE)
target_include_directories(nlohmann_json SYSTEM INTERFACE "${nlohmann_json_SOURCE_DIR}")
target_compile_definitions(nlohmann_json INTERFACE SIMDJSON_COMPETITION_NLOHMANN_JSON)
import_dependency(json11 dropbox/json11 ec4e452)
add_library(json11 STATIC "${json11_SOURCE_DIR}/json11.cpp")
target_include_directories(json11 SYSTEM PUBLIC "${json11_SOURCE_DIR}")
target_compile_definitions(json11 INTERFACE SIMDJSON_COMPETITION_JSON11)
set(jsoncpp_SOURCE_DIR "${simdjson_SOURCE_DIR}/dependencies/jsoncppdist")
add_library(jsoncpp STATIC "${jsoncpp_SOURCE_DIR}/jsoncpp.cpp")
target_include_directories(jsoncpp SYSTEM PUBLIC "${jsoncpp_SOURCE_DIR}")
target_compile_definitions(jsoncpp INTERFACE SIMDJSON_COMPETITION_JSONCPP)
import_dependency(rapidjson Tencent/rapidjson b32cd94)
add_library(rapidjson INTERFACE)
target_compile_definitions(rapidjson INTERFACE RAPIDJSON_HAS_STDSTRING)
target_include_directories(rapidjson SYSTEM INTERFACE
"${rapidjson_SOURCE_DIR}/include")
target_compile_definitions(rapidjson INTERFACE SIMDJSON_COMPETITION_RAPIDJSON)
import_dependency(sajson chadaustin/sajson 2dcfd35)
add_library(sajson INTERFACE)
target_compile_definitions(sajson INTERFACE SAJSON_UNSORTED_OBJECT_KEYS)
target_include_directories(sajson SYSTEM INTERFACE
"${sajson_SOURCE_DIR}/include")
target_compile_definitions(sajson INTERFACE SIMDJSON_COMPETITION_SAJSON)
import_dependency(ujson4c esnme/ujson4c e14f3fd)
add_library(ujson4c STATIC
@ -97,13 +107,16 @@ int main() {}
target_include_directories(ujson4c SYSTEM PUBLIC
"${ujson4c_SOURCE_DIR}/src"
"${ujson4c_SOURCE_DIR}/3rdparty")
target_compile_definitions(ujson4c INTERFACE SIMDJSON_COMPETITION_UJSON4C)
import_dependency(yyjson ibireme/yyjson aa33ec5)
add_library(yyjson STATIC "${yyjson_SOURCE_DIR}/src/yyjson.c")
target_include_directories(yyjson SYSTEM PUBLIC "${yyjson_SOURCE_DIR}/src")
target_compile_definitions(yyjson INTERFACE SIMDJSON_COMPETITION_YYJSON)
add_library(competition-core INTERFACE)
target_link_libraries(competition-core INTERFACE nlohmann_json rapidjson sajson cjson jsmn yyjson)
if(USE_BOOST_JSON)
target_compile_definitions(boostjson INTERFACE HAS_BOOST_JSON)
target_link_libraries(competition-core INTERFACE boostjson)