add boost.json to benchmark (#1202)
Add boost.json to the benchmark. It was accepted into boost 20201003, see https://lists.boost.org/Archives/boost/2020/10/250129.php. The upstream repo is (expected to eventually be migrated to boost): https://github.com/CPPAlliance/json
This commit is contained in:
parent
a540e6afc5
commit
04267e0f6b
|
@ -34,3 +34,6 @@
|
||||||
[submodule "dependencies/cxxopts"]
|
[submodule "dependencies/cxxopts"]
|
||||||
path = dependencies/cxxopts
|
path = dependencies/cxxopts
|
||||||
url = https://github.com/jarro2783/cxxopts
|
url = https://github.com/jarro2783/cxxopts
|
||||||
|
[submodule "dependencies/boost.json"]
|
||||||
|
path = dependencies/boost.json
|
||||||
|
url = https://github.com/CPPAlliance/json.git
|
||||||
|
|
|
@ -25,12 +25,16 @@ target_compile_definitions(parse_nostringparsing PRIVATE SIMDJSON_SKIPSTRINGPARS
|
||||||
if (TARGET competition-all)
|
if (TARGET competition-all)
|
||||||
add_executable(distinctuseridcompetition distinctuseridcompetition.cpp)
|
add_executable(distinctuseridcompetition distinctuseridcompetition.cpp)
|
||||||
target_link_libraries(distinctuseridcompetition competition-core)
|
target_link_libraries(distinctuseridcompetition competition-core)
|
||||||
|
|
||||||
add_executable(minifiercompetition minifiercompetition.cpp)
|
add_executable(minifiercompetition minifiercompetition.cpp)
|
||||||
target_link_libraries(minifiercompetition competition-core)
|
target_link_libraries(minifiercompetition competition-core)
|
||||||
|
|
||||||
add_executable(parseandstatcompetition parseandstatcompetition.cpp)
|
add_executable(parseandstatcompetition parseandstatcompetition.cpp)
|
||||||
target_link_libraries(parseandstatcompetition competition-core)
|
target_link_libraries(parseandstatcompetition competition-core)
|
||||||
|
|
||||||
add_executable(parsingcompetition parsingcompetition.cpp)
|
add_executable(parsingcompetition parsingcompetition.cpp)
|
||||||
target_link_libraries(parsingcompetition competition-core)
|
target_link_libraries(parsingcompetition competition-core)
|
||||||
|
|
||||||
add_executable(allparsingcompetition parsingcompetition.cpp)
|
add_executable(allparsingcompetition parsingcompetition.cpp)
|
||||||
target_link_libraries(allparsingcompetition competition-all)
|
target_link_libraries(allparsingcompetition competition-all)
|
||||||
target_compile_definitions(allparsingcompetition PRIVATE ALLPARSER)
|
target_compile_definitions(allparsingcompetition PRIVATE ALLPARSER)
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
#define BEST_TIME(name, test, expected, pre, repeat, size, verbose) \
|
#define BEST_TIME(name, test, expected, pre, repeat, size, verbose) \
|
||||||
do { \
|
do { \
|
||||||
if (verbose) \
|
if (verbose) \
|
||||||
printf("%-40s\t: ", name); \
|
std::printf("%-40s\t: ", name); \
|
||||||
else \
|
else \
|
||||||
printf("\"%-40s\"", name); \
|
std::printf("\"%-40s\"", name); \
|
||||||
fflush(NULL); \
|
fflush(NULL); \
|
||||||
event_collector collector; \
|
event_collector collector; \
|
||||||
event_aggregate aggregate{}; \
|
event_aggregate aggregate{}; \
|
||||||
|
@ -23,7 +23,8 @@
|
||||||
std::atomic_thread_fence(std::memory_order_acquire); \
|
std::atomic_thread_fence(std::memory_order_acquire); \
|
||||||
collector.start(); \
|
collector.start(); \
|
||||||
if (test != expected) { \
|
if (test != expected) { \
|
||||||
fprintf(stderr, "not expected (%d , %d )", (int)test, (int)expected); \
|
std::fprintf(stderr, "not expected (%d , %d )", (int)test, \
|
||||||
|
(int)expected); \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
std::atomic_thread_fence(std::memory_order_release); \
|
std::atomic_thread_fence(std::memory_order_release); \
|
||||||
|
@ -31,39 +32,40 @@
|
||||||
aggregate << allocate_count; \
|
aggregate << allocate_count; \
|
||||||
} \
|
} \
|
||||||
if (collector.has_events()) { \
|
if (collector.has_events()) { \
|
||||||
printf("%7.3f", aggregate.best.cycles() / static_cast<double>(size)); \
|
std::printf("%7.3f", \
|
||||||
|
aggregate.best.cycles() / static_cast<double>(size)); \
|
||||||
if (verbose) { \
|
if (verbose) { \
|
||||||
printf(" cycles/byte "); \
|
std::printf(" cycles/byte "); \
|
||||||
} \
|
} \
|
||||||
printf("\t"); \
|
std::printf("\t"); \
|
||||||
printf("%7.3f", \
|
std::printf("%7.3f", \
|
||||||
aggregate.best.instructions() / static_cast<double>(size)); \
|
aggregate.best.instructions() / static_cast<double>(size)); \
|
||||||
if (verbose) { \
|
if (verbose) { \
|
||||||
printf(" instructions/byte "); \
|
std::printf(" instructions/byte "); \
|
||||||
} \
|
} \
|
||||||
printf("\t"); \
|
std::printf("\t"); \
|
||||||
} \
|
} \
|
||||||
double gb = static_cast<double>(size) / 1000000000.0; \
|
double gb = static_cast<double>(size) / 1000000000.0; \
|
||||||
printf("%7.3f", gb / aggregate.best.elapsed_sec()); \
|
std::printf("%7.3f", gb / aggregate.best.elapsed_sec()); \
|
||||||
if (verbose) { \
|
if (verbose) { \
|
||||||
printf(" GB/s "); \
|
std::printf(" GB/s "); \
|
||||||
} \
|
} \
|
||||||
printf("%7.3f", 1.0 / aggregate.best.elapsed_sec()); \
|
std::printf("%7.3f", 1.0 / aggregate.best.elapsed_sec()); \
|
||||||
if (verbose) { \
|
if (verbose) { \
|
||||||
printf(" documents/s "); \
|
std::printf(" documents/s "); \
|
||||||
} \
|
} \
|
||||||
printf("\n"); \
|
std::printf("\n"); \
|
||||||
fflush(NULL); \
|
std::fflush(NULL); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// like BEST_TIME, but no check
|
// like BEST_TIME, but no check
|
||||||
#define BEST_TIME_NOCHECK(name, test, pre, repeat, size, verbose) \
|
#define BEST_TIME_NOCHECK(name, test, pre, repeat, size, verbose) \
|
||||||
do { \
|
do { \
|
||||||
if (verbose) \
|
if (verbose) \
|
||||||
printf("%-40s\t: ", name); \
|
std::printf("%-40s\t: ", name); \
|
||||||
else \
|
else \
|
||||||
printf("\"%-40s\"", name); \
|
std::printf("\"%-40s\"", name); \
|
||||||
fflush(NULL); \
|
std::fflush(NULL); \
|
||||||
event_collector collector; \
|
event_collector collector; \
|
||||||
event_aggregate aggregate{}; \
|
event_aggregate aggregate{}; \
|
||||||
for (decltype(repeat) i = 0; i < repeat; i++) { \
|
for (decltype(repeat) i = 0; i < repeat; i++) { \
|
||||||
|
@ -76,29 +78,30 @@
|
||||||
aggregate << allocate_count; \
|
aggregate << allocate_count; \
|
||||||
} \
|
} \
|
||||||
if (collector.has_events()) { \
|
if (collector.has_events()) { \
|
||||||
printf("%7.3f", aggregate.best.cycles() / static_cast<double>(size)); \
|
std::printf("%7.3f", \
|
||||||
|
aggregate.best.cycles() / static_cast<double>(size)); \
|
||||||
if (verbose) { \
|
if (verbose) { \
|
||||||
printf(" cycles/byte "); \
|
std::printf(" cycles/byte "); \
|
||||||
} \
|
} \
|
||||||
printf("\t"); \
|
std::printf("\t"); \
|
||||||
printf("%7.3f", \
|
std::printf("%7.3f", \
|
||||||
aggregate.best.instructions() / static_cast<double>(size)); \
|
aggregate.best.instructions() / static_cast<double>(size)); \
|
||||||
if (verbose) { \
|
if (verbose) { \
|
||||||
printf(" instructions/byte "); \
|
std::printf(" instructions/byte "); \
|
||||||
} \
|
} \
|
||||||
printf("\t"); \
|
std::printf("\t"); \
|
||||||
} \
|
} \
|
||||||
double gb = static_cast<double>(size) / 1000000000.0; \
|
double gb = static_cast<double>(size) / 1000000000.0; \
|
||||||
printf("%7.3f", gb / aggregate.best.elapsed_sec()); \
|
std::printf("%7.3f", gb / aggregate.best.elapsed_sec()); \
|
||||||
if (verbose) { \
|
if (verbose) { \
|
||||||
printf(" GB/s "); \
|
std::printf(" GB/s "); \
|
||||||
} \
|
} \
|
||||||
printf("%7.3f", 1.0 / aggregate.best.elapsed_sec()); \
|
std::printf("%7.3f", 1.0 / aggregate.best.elapsed_sec()); \
|
||||||
if (verbose) { \
|
if (verbose) { \
|
||||||
printf(" documents/s "); \
|
std::printf(" documents/s "); \
|
||||||
} \
|
} \
|
||||||
printf("\n"); \
|
std::printf("\n"); \
|
||||||
fflush(NULL); \
|
std::fflush(NULL); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,6 +26,8 @@ SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
#include <boost/json/parse.hpp>
|
||||||
|
|
||||||
#ifdef ALLPARSER
|
#ifdef ALLPARSER
|
||||||
|
|
||||||
#include "fastjson.cpp"
|
#include "fastjson.cpp"
|
||||||
|
@ -65,32 +67,35 @@ bool fastjson_parse(const char *input) {
|
||||||
// end of fastjson stuff
|
// end of fastjson stuff
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
simdjson_never_inline size_t sum_line_lengths(std::stringstream & is) {
|
simdjson_never_inline size_t sum_line_lengths(std::stringstream &is) {
|
||||||
std::string line;
|
std::string line;
|
||||||
size_t sumofalllinelengths{0};
|
size_t sumofalllinelengths{0};
|
||||||
while(std::getline(is, line)) {
|
while (std::getline(is, line)) {
|
||||||
sumofalllinelengths += line.size();
|
sumofalllinelengths += line.size();
|
||||||
}
|
}
|
||||||
return sumofalllinelengths;
|
return sumofalllinelengths;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void reset_stream(std::stringstream & is) {
|
inline void reset_stream(std::stringstream &is) {
|
||||||
is.clear();
|
is.clear();
|
||||||
is.seekg(0,std::ios::beg);
|
is.seekg(0, std::ios::beg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool bench(const char *filename, bool verbose, bool just_data,
|
||||||
|
double repeat_multiplier) {
|
||||||
bool bench(const char *filename, bool verbose, bool just_data, double repeat_multiplier) {
|
|
||||||
simdjson::padded_string p;
|
simdjson::padded_string p;
|
||||||
auto error = simdjson::padded_string::load(filename).get(p);
|
auto error = simdjson::padded_string::load(filename).get(p);
|
||||||
if (error) {
|
if (error) {
|
||||||
std::cerr << "Could not load the file " << filename << ": " << error << std::endl;
|
std::cerr << "Could not load the file " << filename << ": " << error
|
||||||
|
<< std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int repeat = static_cast<int>((50000000 * repeat_multiplier) / static_cast<double>(p.size()));
|
int repeat = static_cast<int>((50000000 * repeat_multiplier) /
|
||||||
if (repeat < 10) { repeat = 10; }
|
static_cast<double>(p.size()));
|
||||||
|
if (repeat < 10) {
|
||||||
|
repeat = 10;
|
||||||
|
}
|
||||||
// Gigabyte: https://en.wikipedia.org/wiki/Gigabyte
|
// Gigabyte: https://en.wikipedia.org/wiki/Gigabyte
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
std::cout << "Input " << filename << " has ";
|
std::cout << "Input " << filename << " has ";
|
||||||
|
@ -104,68 +109,81 @@ bool bench(const char *filename, bool verbose, bool just_data, double repeat_mul
|
||||||
}
|
}
|
||||||
size_t volume = p.size();
|
size_t volume = p.size();
|
||||||
if (just_data) {
|
if (just_data) {
|
||||||
printf("%-42s %20s %20s %20s %20s \n", "name", "cycles_per_byte",
|
std::printf("%-42s %20s %20s %20s %20s \n", "name", "cycles_per_byte",
|
||||||
"cycles_per_byte_err", "gb_per_s", "gb_per_s_err");
|
"cycles_per_byte_err", "gb_per_s", "gb_per_s_err");
|
||||||
}
|
}
|
||||||
if (!just_data) {
|
if (!just_data) {
|
||||||
const std::string inputcopy(p.data(), p.data()+p.size());
|
const std::string inputcopy(p.data(), p.data() + p.size());
|
||||||
std::stringstream is;
|
std::stringstream is;
|
||||||
is.str(inputcopy);
|
is.str(inputcopy);
|
||||||
const size_t lc = sum_line_lengths(is);
|
const size_t lc = sum_line_lengths(is);
|
||||||
BEST_TIME("getline ",sum_line_lengths(is) , lc, reset_stream(is),
|
BEST_TIME("getline ", sum_line_lengths(is), lc, reset_stream(is), repeat,
|
||||||
repeat, volume, !just_data);
|
volume, !just_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!just_data) {
|
if (!just_data) {
|
||||||
auto parse_dynamic=[](auto& str){
|
auto parse_dynamic = [](auto &str) {
|
||||||
simdjson::dom::parser parser;
|
simdjson::dom::parser parser;
|
||||||
return parser.parse(str).error();
|
return parser.parse(str).error();
|
||||||
};
|
};
|
||||||
BEST_TIME("simdjson (dynamic mem) ", parse_dynamic(p), simdjson::SUCCESS,
|
BEST_TIME("simdjson (dynamic mem) ", parse_dynamic(p), simdjson::SUCCESS, ,
|
||||||
, repeat, volume, !just_data);
|
repeat, volume, !just_data);
|
||||||
}
|
}
|
||||||
// (static alloc)
|
// (static alloc)
|
||||||
simdjson::dom::parser parser;
|
simdjson::dom::parser parser;
|
||||||
BEST_TIME("simdjson ", parser.parse(p).error(), simdjson::SUCCESS, , repeat, volume,
|
BEST_TIME("simdjson ", parser.parse(p).error(), simdjson::SUCCESS, , repeat,
|
||||||
!just_data);
|
volume, !just_data);
|
||||||
|
|
||||||
rapidjson::Document d;
|
rapidjson::Document d;
|
||||||
|
|
||||||
char *buffer = (char *)malloc(p.size() + 1);
|
char *buffer = (char *)std::malloc(p.size() + 1);
|
||||||
memcpy(buffer, p.data(), p.size());
|
std::memcpy(buffer, p.data(), p.size());
|
||||||
buffer[p.size()] = '\0';
|
buffer[p.size()] = '\0';
|
||||||
#ifndef ALLPARSER
|
#ifndef ALLPARSER
|
||||||
if (!just_data)
|
if (!just_data)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
memcpy(buffer, p.data(), p.size());
|
std::memcpy(buffer, p.data(), p.size());
|
||||||
BEST_TIME("RapidJSON ",
|
BEST_TIME("RapidJSON ",
|
||||||
d.Parse<kParseValidateEncodingFlag>((const char *)buffer)
|
d.Parse<kParseValidateEncodingFlag>((const char *)buffer)
|
||||||
.HasParseError(),
|
.HasParseError(),
|
||||||
false, , repeat, volume,
|
false, , repeat, volume, !just_data);
|
||||||
!just_data);
|
|
||||||
}
|
}
|
||||||
#ifndef ALLPARSER
|
#ifndef ALLPARSER
|
||||||
if (!just_data)
|
if (!just_data)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
memcpy(buffer, p.data(), p.size());
|
std::memcpy(buffer, p.data(), p.size());
|
||||||
BEST_TIME("RapidJSON (accurate number parsing) ",
|
BEST_TIME("RapidJSON (accurate number parsing) ",
|
||||||
d.Parse<kParseValidateEncodingFlag|kParseFullPrecisionFlag>((const char *)buffer)
|
d.Parse<kParseValidateEncodingFlag | kParseFullPrecisionFlag>(
|
||||||
|
(const char *)buffer)
|
||||||
.HasParseError(),
|
.HasParseError(),
|
||||||
false, , repeat, volume,
|
false, , repeat, volume, !just_data);
|
||||||
!just_data);
|
|
||||||
}
|
}
|
||||||
BEST_TIME("RapidJSON (insitu)",
|
BEST_TIME(
|
||||||
d.ParseInsitu<kParseValidateEncodingFlag>(buffer).HasParseError(),
|
"RapidJSON (insitu)",
|
||||||
false,
|
d.ParseInsitu<kParseValidateEncodingFlag>(buffer).HasParseError(), false,
|
||||||
memcpy(buffer, p.data(), p.size()) && (buffer[p.size()] = '\0'),
|
std::memcpy(buffer, p.data(), p.size()) && (buffer[p.size()] = '\0'),
|
||||||
repeat, volume, !just_data);
|
repeat, volume, !just_data);
|
||||||
BEST_TIME("RapidJSON (insitu, accurate number parsing)",
|
BEST_TIME("RapidJSON (insitu, accurate number parsing)",
|
||||||
d.ParseInsitu<kParseValidateEncodingFlag|kParseFullPrecisionFlag>(buffer).HasParseError(),
|
d.ParseInsitu<kParseValidateEncodingFlag | kParseFullPrecisionFlag>(
|
||||||
|
buffer)
|
||||||
|
.HasParseError(),
|
||||||
false,
|
false,
|
||||||
memcpy(buffer, p.data(), p.size()) && (buffer[p.size()] = '\0'),
|
std::memcpy(buffer, p.data(), p.size()) &&
|
||||||
|
(buffer[p.size()] = '\0'),
|
||||||
repeat, volume, !just_data);
|
repeat, volume, !just_data);
|
||||||
|
|
||||||
|
{
|
||||||
|
const boost::json::string_view sv(p.data(), p.size());
|
||||||
|
auto execute = [](auto sv) -> bool {
|
||||||
|
boost::json::error_code ec;
|
||||||
|
auto jv = boost::json::parse(sv, ec);
|
||||||
|
return !!ec;
|
||||||
|
};
|
||||||
|
|
||||||
|
BEST_TIME("Boost.json", execute(sv), false, , repeat, volume, !just_data);
|
||||||
|
}
|
||||||
#ifndef ALLPARSER
|
#ifndef ALLPARSER
|
||||||
if (!just_data)
|
if (!just_data)
|
||||||
#endif
|
#endif
|
||||||
|
@ -173,59 +191,61 @@ bool bench(const char *filename, bool verbose, bool just_data, double repeat_mul
|
||||||
sajson::parse(sajson::dynamic_allocation(),
|
sajson::parse(sajson::dynamic_allocation(),
|
||||||
sajson::mutable_string_view(p.size(), buffer))
|
sajson::mutable_string_view(p.size(), buffer))
|
||||||
.is_valid(),
|
.is_valid(),
|
||||||
true, memcpy(buffer, p.data(), p.size()), repeat, volume,
|
true, std::memcpy(buffer, p.data(), p.size()), repeat, volume,
|
||||||
!just_data);
|
!just_data);
|
||||||
|
|
||||||
size_t ast_buffer_size = p.size();
|
size_t ast_buffer_size = p.size();
|
||||||
size_t *ast_buffer = (size_t *)malloc(ast_buffer_size * sizeof(size_t));
|
size_t *ast_buffer = (size_t *)std::malloc(ast_buffer_size * sizeof(size_t));
|
||||||
// (static alloc, insitu)
|
// (static alloc, insitu)
|
||||||
BEST_TIME(
|
BEST_TIME(
|
||||||
"sajson",
|
"sajson",
|
||||||
sajson::parse(sajson::bounded_allocation(ast_buffer, ast_buffer_size),
|
sajson::parse(sajson::bounded_allocation(ast_buffer, ast_buffer_size),
|
||||||
sajson::mutable_string_view(p.size(), buffer))
|
sajson::mutable_string_view(p.size(), buffer))
|
||||||
.is_valid(),
|
.is_valid(),
|
||||||
true, memcpy(buffer, p.data(), p.size()), repeat, volume, !just_data);
|
true, std::memcpy(buffer, p.data(), p.size()), repeat, volume,
|
||||||
|
!just_data);
|
||||||
|
|
||||||
memcpy(buffer, p.data(), p.size());
|
std::memcpy(buffer, p.data(), p.size());
|
||||||
size_t expected = json::parse(p.data(), p.data() + p.size()).size();
|
size_t expected = json::parse(p.data(), p.data() + p.size()).size();
|
||||||
BEST_TIME("nlohmann-json", json::parse(buffer, buffer + p.size()).size(),
|
BEST_TIME("nlohmann-json", json::parse(buffer, buffer + p.size()).size(),
|
||||||
expected, , repeat, volume,
|
expected, , repeat, volume, !just_data);
|
||||||
!just_data);
|
|
||||||
|
|
||||||
#ifdef ALLPARSER
|
#ifdef ALLPARSER
|
||||||
std::string json11err;
|
std::string json11err;
|
||||||
BEST_TIME("dropbox (json11) ",
|
BEST_TIME("dropbox (json11) ",
|
||||||
((json11::Json::parse(buffer, json11err).is_null()) ||
|
((json11::Json::parse(buffer, json11err).is_null()) ||
|
||||||
(!json11err.empty())),
|
(!json11err.empty())),
|
||||||
false, memcpy(buffer, p.data(), p.size()), repeat, volume,
|
false, std::memcpy(buffer, p.data(), p.size()), repeat, volume,
|
||||||
!just_data);
|
!just_data);
|
||||||
|
|
||||||
BEST_TIME("fastjson ", fastjson_parse(buffer), true,
|
BEST_TIME("fastjson ", fastjson_parse(buffer), true,
|
||||||
memcpy(buffer, p.data(), p.size()), repeat, volume, !just_data);
|
std::memcpy(buffer, p.data(), p.size()), repeat, volume,
|
||||||
|
!just_data);
|
||||||
JsonValue value;
|
JsonValue value;
|
||||||
JsonAllocator allocator;
|
JsonAllocator allocator;
|
||||||
char *endptr;
|
char *endptr;
|
||||||
BEST_TIME("gason ", jsonParse(buffer, &endptr, &value, allocator),
|
BEST_TIME("gason ", jsonParse(buffer, &endptr, &value, allocator),
|
||||||
JSON_OK, memcpy(buffer, p.data(), p.size()), repeat, volume,
|
JSON_OK, std::memcpy(buffer, p.data(), p.size()), repeat, volume,
|
||||||
!just_data);
|
!just_data);
|
||||||
void *state;
|
void *state;
|
||||||
BEST_TIME("ultrajson ",
|
BEST_TIME("ultrajson ",
|
||||||
(UJDecode(buffer, p.size(), NULL, &state) == NULL), false,
|
(UJDecode(buffer, p.size(), NULL, &state) == NULL), false,
|
||||||
memcpy(buffer, p.data(), p.size()), repeat, volume, !just_data);
|
std::memcpy(buffer, p.data(), p.size()), repeat, volume,
|
||||||
|
!just_data);
|
||||||
|
|
||||||
{
|
{
|
||||||
std::unique_ptr<jsmntok_t[]> tokens =
|
std::unique_ptr<jsmntok_t[]> tokens =
|
||||||
std::make_unique<jsmntok_t[]>(p.size());
|
std::make_unique<jsmntok_t[]>(p.size());
|
||||||
jsmn_parser jparser;
|
jsmn_parser jparser;
|
||||||
jsmn_init(&jparser);
|
jsmn_init(&jparser);
|
||||||
memcpy(buffer, p.data(), p.size());
|
std::memcpy(buffer, p.data(), p.size());
|
||||||
buffer[p.size()] = '\0';
|
buffer[p.size()] = '\0';
|
||||||
BEST_TIME(
|
BEST_TIME("jsmn ",
|
||||||
"jsmn ",
|
(jsmn_parse(&jparser, buffer, p.size(), tokens.get(),
|
||||||
(jsmn_parse(&jparser, buffer, p.size(), tokens.get(), static_cast<unsigned int>(p.size())) > 0),
|
static_cast<unsigned int>(p.size())) > 0),
|
||||||
true, jsmn_init(&jparser), repeat, volume, !just_data);
|
true, jsmn_init(&jparser), repeat, volume, !just_data);
|
||||||
}
|
}
|
||||||
memcpy(buffer, p.data(), p.size());
|
std::memcpy(buffer, p.data(), p.size());
|
||||||
buffer[p.size()] = '\0';
|
buffer[p.size()] = '\0';
|
||||||
cJSON *tree = cJSON_Parse(buffer);
|
cJSON *tree = cJSON_Parse(buffer);
|
||||||
BEST_TIME("cJSON ", ((tree = cJSON_Parse(buffer)) != NULL), true,
|
BEST_TIME("cJSON ", ((tree = cJSON_Parse(buffer)) != NULL), true,
|
||||||
|
@ -243,12 +263,13 @@ bool bench(const char *filename, bool verbose, bool just_data, double repeat_mul
|
||||||
#endif
|
#endif
|
||||||
if (!just_data)
|
if (!just_data)
|
||||||
BEST_TIME("memcpy ",
|
BEST_TIME("memcpy ",
|
||||||
(memcpy(buffer, p.data(), p.size()) == buffer), true, , repeat,
|
(std::memcpy(buffer, p.data(), p.size()) == buffer), true, ,
|
||||||
volume, !just_data);
|
repeat, volume, !just_data);
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
if (!just_data) {
|
if (!just_data) {
|
||||||
printf("\n \n <doing additional analysis with performance counters (Linux "
|
std::printf(
|
||||||
"only)>\n");
|
"\n \n <doing additional analysis with performance counters (Linux "
|
||||||
|
"only)>\n");
|
||||||
std::vector<int> evts;
|
std::vector<int> evts;
|
||||||
evts.push_back(PERF_COUNT_HW_CPU_CYCLES);
|
evts.push_back(PERF_COUNT_HW_CPU_CYCLES);
|
||||||
evts.push_back(PERF_COUNT_HW_INSTRUCTIONS);
|
evts.push_back(PERF_COUNT_HW_INSTRUCTIONS);
|
||||||
|
@ -265,64 +286,84 @@ bool bench(const char *filename, bool verbose, bool just_data, double repeat_mul
|
||||||
unified.start();
|
unified.start();
|
||||||
auto parse_error = parser.parse(p).error();
|
auto parse_error = parser.parse(p).error();
|
||||||
if (parse_error)
|
if (parse_error)
|
||||||
printf("bug\n");
|
std::printf("bug\n");
|
||||||
unified.end(results);
|
unified.end(results);
|
||||||
std::transform(stats.begin(), stats.end(), results.begin(), stats.begin(),
|
std::transform(stats.begin(), stats.end(), results.begin(), stats.begin(),
|
||||||
std::plus<unsigned long long>());
|
std::plus<unsigned long long>());
|
||||||
}
|
}
|
||||||
printf("simdjson : cycles %10.0f instructions %10.0f branchmisses %10.0f "
|
std::printf(
|
||||||
"cacheref %10.0f cachemisses %10.0f bytespercachemiss %10.0f "
|
"simdjson : cycles %10.0f instructions %10.0f branchmisses %10.0f "
|
||||||
"inspercycle %10.1f insperbyte %10.1f\n",
|
"cacheref %10.0f cachemisses %10.0f bytespercachemiss %10.0f "
|
||||||
static_cast<double>(stats[0]) / static_cast<double>(repeat), static_cast<double>(stats[1]) / static_cast<double>(repeat),
|
"inspercycle %10.1f insperbyte %10.1f\n",
|
||||||
static_cast<double>(stats[2]) / static_cast<double>(repeat), static_cast<double>(stats[3]) / static_cast<double>(repeat),
|
static_cast<double>(stats[0]) / static_cast<double>(repeat),
|
||||||
static_cast<double>(stats[4]) / static_cast<double>(repeat), static_cast<double>(volume) * static_cast<double>(repeat) / static_cast<double>(stats[2]),
|
static_cast<double>(stats[1]) / static_cast<double>(repeat),
|
||||||
static_cast<double>(stats[1]) / static_cast<double>(stats[0]), static_cast<double>(stats[1]) / (static_cast<double>(volume) * static_cast<double>(repeat)));
|
static_cast<double>(stats[2]) / static_cast<double>(repeat),
|
||||||
|
static_cast<double>(stats[3]) / static_cast<double>(repeat),
|
||||||
|
static_cast<double>(stats[4]) / static_cast<double>(repeat),
|
||||||
|
static_cast<double>(volume) * static_cast<double>(repeat) /
|
||||||
|
static_cast<double>(stats[2]),
|
||||||
|
static_cast<double>(stats[1]) / static_cast<double>(stats[0]),
|
||||||
|
static_cast<double>(stats[1]) /
|
||||||
|
(static_cast<double>(volume) * static_cast<double>(repeat)));
|
||||||
|
|
||||||
std::fill(stats.begin(), stats.end(), 0);
|
std::fill(stats.begin(), stats.end(), 0);
|
||||||
for (decltype(repeat) i = 0; i < repeat; i++) {
|
for (decltype(repeat) i = 0; i < repeat; i++) {
|
||||||
memcpy(buffer, p.data(), p.size());
|
std::memcpy(buffer, p.data(), p.size());
|
||||||
buffer[p.size()] = '\0';
|
buffer[p.size()] = '\0';
|
||||||
unified.start();
|
unified.start();
|
||||||
if (d.ParseInsitu<kParseValidateEncodingFlag>(buffer).HasParseError() !=
|
if (d.ParseInsitu<kParseValidateEncodingFlag>(buffer).HasParseError() !=
|
||||||
false)
|
false)
|
||||||
printf("bug\n");
|
std::printf("bug\n");
|
||||||
unified.end(results);
|
unified.end(results);
|
||||||
std::transform(stats.begin(), stats.end(), results.begin(), stats.begin(),
|
std::transform(stats.begin(), stats.end(), results.begin(), stats.begin(),
|
||||||
std::plus<unsigned long long>());
|
std::plus<unsigned long long>());
|
||||||
}
|
}
|
||||||
printf("RapidJSON: cycles %10.0f instructions %10.0f branchmisses %10.0f "
|
std::printf(
|
||||||
"cacheref %10.0f cachemisses %10.0f bytespercachemiss %10.0f "
|
"RapidJSON: cycles %10.0f instructions %10.0f branchmisses %10.0f "
|
||||||
"inspercycle %10.1f insperbyte %10.1f\n",
|
"cacheref %10.0f cachemisses %10.0f bytespercachemiss %10.0f "
|
||||||
static_cast<double>(stats[0]) / static_cast<double>(repeat), static_cast<double>(stats[1]) / static_cast<double>(repeat),
|
"inspercycle %10.1f insperbyte %10.1f\n",
|
||||||
static_cast<double>(stats[2]) / static_cast<double>(repeat), static_cast<double>(stats[3]) / static_cast<double>(repeat),
|
static_cast<double>(stats[0]) / static_cast<double>(repeat),
|
||||||
static_cast<double>(stats[4]) / static_cast<double>(repeat), static_cast<double>(volume) * static_cast<double>(repeat) / static_cast<double>(stats[2]),
|
static_cast<double>(stats[1]) / static_cast<double>(repeat),
|
||||||
static_cast<double>(stats[1]) / static_cast<double>(stats[0]), static_cast<double>(stats[1]) / (static_cast<double>(volume) * static_cast<double>(repeat)));
|
static_cast<double>(stats[2]) / static_cast<double>(repeat),
|
||||||
|
static_cast<double>(stats[3]) / static_cast<double>(repeat),
|
||||||
|
static_cast<double>(stats[4]) / static_cast<double>(repeat),
|
||||||
|
static_cast<double>(volume) * static_cast<double>(repeat) /
|
||||||
|
static_cast<double>(stats[2]),
|
||||||
|
static_cast<double>(stats[1]) / static_cast<double>(stats[0]),
|
||||||
|
static_cast<double>(stats[1]) /
|
||||||
|
(static_cast<double>(volume) * static_cast<double>(repeat)));
|
||||||
|
|
||||||
std::fill(stats.begin(), stats.end(), 0); // unnecessary
|
std::fill(stats.begin(), stats.end(), 0); // unnecessary
|
||||||
for (decltype(repeat) i = 0; i < repeat; i++) {
|
for (decltype(repeat) i = 0; i < repeat; i++) {
|
||||||
memcpy(buffer, p.data(), p.size());
|
std::memcpy(buffer, p.data(), p.size());
|
||||||
unified.start();
|
unified.start();
|
||||||
if (sajson::parse(sajson::bounded_allocation(ast_buffer, ast_buffer_size),
|
if (sajson::parse(sajson::bounded_allocation(ast_buffer, ast_buffer_size),
|
||||||
sajson::mutable_string_view(p.size(), buffer))
|
sajson::mutable_string_view(p.size(), buffer))
|
||||||
.is_valid() != true)
|
.is_valid() != true)
|
||||||
printf("bug\n");
|
std::printf("bug\n");
|
||||||
unified.end(results);
|
unified.end(results);
|
||||||
std::transform(stats.begin(), stats.end(), results.begin(), stats.begin(),
|
std::transform(stats.begin(), stats.end(), results.begin(), stats.begin(),
|
||||||
std::plus<unsigned long long>());
|
std::plus<unsigned long long>());
|
||||||
}
|
}
|
||||||
printf("sajson : cycles %10.0f instructions %10.0f branchmisses %10.0f "
|
std::printf(
|
||||||
"cacheref %10.0f cachemisses %10.0f bytespercachemiss %10.0f "
|
"sajson : cycles %10.0f instructions %10.0f branchmisses %10.0f "
|
||||||
"inspercycle %10.1f insperbyte %10.1f\n",
|
"cacheref %10.0f cachemisses %10.0f bytespercachemiss %10.0f "
|
||||||
static_cast<double>(stats[0]) / static_cast<double>(repeat), static_cast<double>(stats[1]) / static_cast<double>(repeat),
|
"inspercycle %10.1f insperbyte %10.1f\n",
|
||||||
static_cast<double>(stats[2]) / static_cast<double>(repeat), static_cast<double>(stats[3]) / static_cast<double>(repeat),
|
static_cast<double>(stats[0]) / static_cast<double>(repeat),
|
||||||
static_cast<double>(stats[4]) / static_cast<double>(repeat), static_cast<double>(volume) * static_cast<double>(repeat) / static_cast<double>(stats[2]),
|
static_cast<double>(stats[1]) / static_cast<double>(repeat),
|
||||||
static_cast<double>(stats[1]) / static_cast<double>(stats[0]), static_cast<double>(stats[1]) / (static_cast<double>(volume) * static_cast<double>(repeat)));
|
static_cast<double>(stats[2]) / static_cast<double>(repeat),
|
||||||
|
static_cast<double>(stats[3]) / static_cast<double>(repeat),
|
||||||
|
static_cast<double>(stats[4]) / static_cast<double>(repeat),
|
||||||
|
static_cast<double>(volume) * static_cast<double>(repeat) /
|
||||||
|
static_cast<double>(stats[2]),
|
||||||
|
static_cast<double>(stats[1]) / static_cast<double>(stats[0]),
|
||||||
|
static_cast<double>(stats[1]) /
|
||||||
|
(static_cast<double>(volume) * static_cast<double>(repeat)));
|
||||||
}
|
}
|
||||||
#endif // __linux__
|
#endif // __linux__
|
||||||
|
|
||||||
free(ast_buffer);
|
std::free(ast_buffer);
|
||||||
free(buffer);
|
std::free(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,13 +390,17 @@ int main(int argc, char *argv[]) {
|
||||||
std::cerr << "Usage: " << argv[0] << " <jsonfile>" << std::endl;
|
std::cerr << "Usage: " << argv[0] << " <jsonfile>" << std::endl;
|
||||||
std::cerr << "Or " << argv[0] << " -v <jsonfile>" << std::endl;
|
std::cerr << "Or " << argv[0] << " -v <jsonfile>" << std::endl;
|
||||||
std::cerr << "The '-t' flag outputs a table." << std::endl;
|
std::cerr << "The '-t' flag outputs a table." << std::endl;
|
||||||
std::cerr << "The '-r <N>' flag sets the repeat multiplier: set it above 1 to do more iterations, and below 1 to do fewer." << std::endl;
|
std::cerr << "The '-r <N>' flag sets the repeat multiplier: set it above 1 "
|
||||||
|
"to do more iterations, and below 1 to do fewer."
|
||||||
|
<< std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
int result = EXIT_SUCCESS;
|
int result = EXIT_SUCCESS;
|
||||||
for (int fileind = optind; fileind < argc; fileind++) {
|
for (int fileind = optind; fileind < argc; fileind++) {
|
||||||
if (!bench(argv[fileind], verbose, just_data, repeat_multiplier)) { result = EXIT_FAILURE; }
|
if (!bench(argv[fileind], verbose, just_data, repeat_multiplier)) {
|
||||||
printf("\n\n");
|
result = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
std::printf("\n\n");
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,8 +67,13 @@ if ((Git_FOUND) AND SIMDJSON_GIT AND (SIMDJSON_IS_UNDER_GIT))
|
||||||
add_library(competition-ujson4c ujson4c/src/ujdecode.c)
|
add_library(competition-ujson4c ujson4c/src/ujdecode.c)
|
||||||
target_include_directories(competition-ujson4c PUBLIC ujson4c/3rdparty ujson4c/src)
|
target_include_directories(competition-ujson4c PUBLIC ujson4c/3rdparty ujson4c/src)
|
||||||
|
|
||||||
|
initialize_submodule(boost.json)
|
||||||
|
add_library(boostjson boost.json/src/src.cpp)
|
||||||
|
target_compile_definitions(boostjson PUBLIC BOOST_JSON_STANDALONE)
|
||||||
|
target_include_directories(boostjson PUBLIC boost.json/include)
|
||||||
|
|
||||||
add_library(competition-core INTERFACE)
|
add_library(competition-core INTERFACE)
|
||||||
target_link_libraries(competition-core INTERFACE competition-json competition-rapidjson competition-sajson competition-cJSON competition-jsmn)
|
target_link_libraries(competition-core INTERFACE competition-json competition-rapidjson competition-sajson competition-cJSON competition-jsmn boostjson)
|
||||||
|
|
||||||
add_library(competition-all INTERFACE)
|
add_library(competition-all INTERFACE)
|
||||||
target_link_libraries(competition-all INTERFACE competition-core competition-jsoncppdist competition-json11 competition-fastjson competition-gason competition-ujson4c)
|
target_link_libraries(competition-all INTERFACE competition-core competition-jsoncppdist competition-json11 competition-fastjson competition-gason competition-ujson4c)
|
||||||
|
@ -81,7 +86,7 @@ if ((Git_FOUND) AND SIMDJSON_GIT AND (SIMDJSON_IS_UNDER_GIT))
|
||||||
else()
|
else()
|
||||||
message(STATUS "Git is unavailable.")
|
message(STATUS "Git is unavailable.")
|
||||||
if(SIMDJSON_COMPETITION)
|
if(SIMDJSON_COMPETITION)
|
||||||
message (STATUS "'SIMDJSON_COMPETITION' is requested, but we cannot download the remote repositories." )
|
message (STATUS "'SIMDJSON_COMPETITION' is requested, but we cannot download the remote repositories." )
|
||||||
endif()
|
endif()
|
||||||
if(SIMDJSON_GOOGLE_BENCHMARKS)
|
if(SIMDJSON_GOOGLE_BENCHMARKS)
|
||||||
message (STATUS "'SIMDJSON_GOOGLE_BENCHMARKS' is requested, but we cannot download the remote repositories." )
|
message (STATUS "'SIMDJSON_GOOGLE_BENCHMARKS' is requested, but we cannot download the remote repositories." )
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit a0983f788b9138211bfc060e68c9973efb3394e4
|
Loading…
Reference in New Issue