Get rid of templates from rapidjson benchmarks
This commit is contained in:
parent
065ea00066
commit
6a595231b0
|
@ -8,13 +8,10 @@ namespace distinct_user_id {
|
|||
|
||||
using namespace rapidjson;
|
||||
|
||||
template<int F>
|
||||
class rapidjson_base {
|
||||
struct rapidjson_base {
|
||||
Document doc{};
|
||||
|
||||
public:
|
||||
bool run(const padded_string &json, std::vector<uint64_t> &ids) {
|
||||
auto &root = doc.Parse<F>(json.data());
|
||||
bool run(Document &root, std::vector<uint64_t> &ids) {
|
||||
if (root.HasParseError() || !root.IsObject()) { return false; }
|
||||
auto statuses = root.FindMember("statuses");
|
||||
if (statuses == root.MemberEnd() || !statuses->value.IsArray()) { return false; }
|
||||
|
@ -41,7 +38,12 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class rapidjson : public rapidjson_base<kParseValidateEncodingFlag> {};
|
||||
struct rapidjson : public rapidjson_base {
|
||||
bool run(const padded_string &json, std::vector<uint64_t> &ids) {
|
||||
return rapidjson_base::run(doc.Parse<kParseValidateEncodingFlag>(json.data()), ids);
|
||||
}
|
||||
};
|
||||
|
||||
BENCHMARK_TEMPLATE(distinct_user_id, rapidjson);
|
||||
|
||||
} // namespace partial_tweets
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace distinct_user_id {
|
|||
|
||||
using namespace simdjson;
|
||||
|
||||
class simdjson_dom {
|
||||
struct simdjson_dom {
|
||||
dom::parser parser{};
|
||||
|
||||
public:
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace distinct_user_id {
|
|||
using namespace simdjson;
|
||||
using namespace simdjson::builtin;
|
||||
|
||||
class simdjson_ondemand {
|
||||
struct simdjson_ondemand {
|
||||
ondemand::parser parser{};
|
||||
public:
|
||||
bool run(const simdjson::padded_string &json, std::vector<uint64_t> &ids) {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
namespace distinct_user_id {
|
||||
|
||||
class yyjson {
|
||||
struct yyjson {
|
||||
public:
|
||||
bool run(const simdjson::padded_string &json, std::vector<uint64_t> &ids) {
|
||||
// Walk the document, parsing the tweets as we go
|
||||
|
|
|
@ -8,13 +8,10 @@ namespace find_tweet {
|
|||
|
||||
using namespace rapidjson;
|
||||
|
||||
template<int F>
|
||||
class rapidjson_base {
|
||||
struct rapidjson_base {
|
||||
Document doc{};
|
||||
|
||||
public:
|
||||
bool run(const padded_string &json, uint64_t find_id, std::string_view &text) {
|
||||
auto &root = doc.Parse<F>(json.data());
|
||||
bool run(Document &root, uint64_t find_id, std::string_view &text) {
|
||||
if (root.HasParseError() || !root.IsObject()) { return false; }
|
||||
auto statuses = root.FindMember("statuses");
|
||||
if (statuses == root.MemberEnd() || !statuses->value.IsArray()) { return false; }
|
||||
|
@ -34,7 +31,11 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class rapidjson : public rapidjson_base<kParseValidateEncodingFlag> {};
|
||||
struct rapidjson : public rapidjson_base {
|
||||
bool run(const padded_string &json, uint64_t find_id, std::string_view &text) {
|
||||
return rapidjson_base::run(doc.Parse<kParseValidateEncodingFlag>(json.data()), find_id, text);
|
||||
}
|
||||
};
|
||||
BENCHMARK_TEMPLATE(find_tweet, rapidjson);
|
||||
|
||||
} // namespace partial_tweets
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace find_tweet {
|
|||
|
||||
using namespace simdjson;
|
||||
|
||||
class simdjson_dom {
|
||||
struct simdjson_dom {
|
||||
dom::parser parser{};
|
||||
public:
|
||||
|
||||
bool run(const simdjson::padded_string &json, uint64_t find_id, std::string_view &text) {
|
||||
text = "";
|
||||
auto doc = parser.parse(json);
|
||||
|
|
|
@ -9,9 +9,9 @@ namespace find_tweet {
|
|||
using namespace simdjson;
|
||||
using namespace simdjson::builtin;
|
||||
|
||||
class simdjson_ondemand {
|
||||
struct simdjson_ondemand {
|
||||
ondemand::parser parser{};
|
||||
public:
|
||||
|
||||
bool run(const simdjson::padded_string &json, uint64_t find_id, std::string_view &text) {
|
||||
// Walk the document, parsing as we go
|
||||
auto doc = parser.iterate(json);
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
|
||||
namespace find_tweet {
|
||||
|
||||
class yyjson {
|
||||
public:
|
||||
struct yyjson {
|
||||
bool run(const simdjson::padded_string &json, uint64_t find_id, std::string_view &text) {
|
||||
// Walk the document, parsing the tweets as we go
|
||||
yyjson_doc *doc = yyjson_read(json.data(), json.size(), 0);
|
||||
|
|
|
@ -8,8 +8,7 @@ namespace kostya {
|
|||
|
||||
using namespace rapidjson;
|
||||
|
||||
template<int F>
|
||||
class rapidjson_base {
|
||||
struct rapidjson_base {
|
||||
Document doc;
|
||||
|
||||
simdjson_really_inline double get_double(Value &object, std::string_view key) {
|
||||
|
@ -19,9 +18,7 @@ class rapidjson_base {
|
|||
return field->value.GetDouble();
|
||||
}
|
||||
|
||||
public:
|
||||
bool run(const simdjson::padded_string &json, std::vector<point> &points) {
|
||||
auto &root = doc.Parse<F>(json.data());
|
||||
bool run(Document &root, std::vector<point> &points) {
|
||||
if (root.HasParseError()) { return false; }
|
||||
if (!root.IsObject()) { return false; }
|
||||
auto coords = root.FindMember("coordinates");
|
||||
|
@ -36,8 +33,18 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class rapidjson : public rapidjson_base<kParseValidateEncodingFlag> {};
|
||||
class rapidjson_lossless : public rapidjson_base<kParseValidateEncodingFlag | kParseFullPrecisionFlag> {};
|
||||
struct rapidjson : public rapidjson_base {
|
||||
bool run(const padded_string &json, std::vector<point> &points) {
|
||||
return rapidjson_base::run(doc.Parse<kParseValidateEncodingFlag>(json.data()), points);
|
||||
}
|
||||
};
|
||||
|
||||
struct rapidjson_lossless : public rapidjson_base {
|
||||
bool run(const padded_string &json, std::vector<point> &points) {
|
||||
return rapidjson_base::run(doc.Parse<kParseValidateEncodingFlag | kParseFullPrecisionFlag>(json.data()), points);
|
||||
}
|
||||
};
|
||||
|
||||
BENCHMARK_TEMPLATE(kostya, rapidjson);
|
||||
BENCHMARK_TEMPLATE(kostya, rapidjson_lossless);
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace kostya {
|
|||
|
||||
using namespace simdjson;
|
||||
|
||||
class simdjson_dom {
|
||||
struct simdjson_dom {
|
||||
dom::parser parser{};
|
||||
public:
|
||||
|
||||
bool run(const simdjson::padded_string &json, std::vector<point> &points) {
|
||||
for (auto point : parser.parse(json)["coordinates"]) {
|
||||
points.emplace_back(kostya::point{point["x"], point["y"], point["z"]});
|
||||
|
|
|
@ -9,9 +9,9 @@ namespace kostya {
|
|||
using namespace simdjson;
|
||||
using namespace simdjson::builtin;
|
||||
|
||||
class simdjson_ondemand {
|
||||
struct simdjson_ondemand {
|
||||
ondemand::parser parser{};
|
||||
public:
|
||||
|
||||
bool run(const simdjson::padded_string &json, std::vector<point> &points) {
|
||||
auto doc = parser.iterate(json);
|
||||
for (ondemand::object point : doc.find_field("coordinates")) {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
namespace kostya {
|
||||
|
||||
class yyjson {
|
||||
struct yyjson {
|
||||
simdjson_really_inline double get_double(yyjson_val *obj, std::string_view key) {
|
||||
yyjson_val *val = yyjson_obj_getn(obj, key.data(), key.length());
|
||||
if (!val) { throw "missing point field!"; }
|
||||
|
@ -24,7 +24,6 @@ class yyjson {
|
|||
}
|
||||
}
|
||||
|
||||
public:
|
||||
bool run(const simdjson::padded_string &json, std::vector<point> &points) {
|
||||
yyjson_doc *doc = yyjson_read(json.data(), json.size(), 0);
|
||||
if (!doc) { return false; }
|
||||
|
|
|
@ -8,8 +8,7 @@ namespace large_random {
|
|||
|
||||
using namespace rapidjson;
|
||||
|
||||
template<int F>
|
||||
class rapidjson_base {
|
||||
struct rapidjson_base {
|
||||
Document doc;
|
||||
|
||||
simdjson_really_inline double get_double(Value &object, std::string_view key) {
|
||||
|
@ -19,9 +18,7 @@ class rapidjson_base {
|
|||
return field->value.GetDouble();
|
||||
}
|
||||
|
||||
public:
|
||||
bool run(const simdjson::padded_string &json, std::vector<point> &points) {
|
||||
auto &coords = doc.Parse<F>(json.data());
|
||||
bool run(Document &coords, std::vector<point> &points) {
|
||||
if (coords.HasParseError()) { return false; }
|
||||
if (!coords.IsArray()) { return false; }
|
||||
for (auto &coord : coords.GetArray()) {
|
||||
|
@ -33,8 +30,18 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class rapidjson : public rapidjson_base<kParseValidateEncodingFlag> {};
|
||||
class rapidjson_lossless : public rapidjson_base<kParseValidateEncodingFlag | kParseFullPrecisionFlag> {};
|
||||
struct rapidjson : public rapidjson_base {
|
||||
bool run(const simdjson::padded_string &json, std::vector<point> &points) {
|
||||
return rapidjson_base::run(doc.Parse<kParseValidateEncodingFlag>(json.data()), points);
|
||||
}
|
||||
};
|
||||
|
||||
struct rapidjson_lossless : public rapidjson_base {
|
||||
bool run(const simdjson::padded_string &json, std::vector<point> &points) {
|
||||
return rapidjson_base::run(doc.Parse<kParseValidateEncodingFlag | kParseFullPrecisionFlag>(json.data()), points);
|
||||
}
|
||||
};
|
||||
|
||||
BENCHMARK_TEMPLATE(large_random, rapidjson);
|
||||
BENCHMARK_TEMPLATE(large_random, rapidjson_lossless);
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ namespace large_random {
|
|||
|
||||
using namespace simdjson;
|
||||
|
||||
class simdjson_dom {
|
||||
struct simdjson_dom {
|
||||
dom::parser parser{};
|
||||
public:
|
||||
|
||||
bool run(const simdjson::padded_string &json, std::vector<point> &points) {
|
||||
for (auto point : parser.parse(json)) {
|
||||
points.emplace_back(large_random::point{point["x"], point["y"], point["z"]});
|
||||
|
|
|
@ -9,9 +9,9 @@ namespace large_random {
|
|||
using namespace simdjson;
|
||||
using namespace simdjson::builtin;
|
||||
|
||||
class simdjson_ondemand {
|
||||
struct simdjson_ondemand {
|
||||
ondemand::parser parser{};
|
||||
public:
|
||||
|
||||
bool run(const simdjson::padded_string &json, std::vector<point> &points) {
|
||||
auto doc = parser.iterate(json);
|
||||
for (ondemand::object coord : doc) {
|
||||
|
|
|
@ -9,9 +9,9 @@ namespace large_random {
|
|||
using namespace simdjson;
|
||||
using namespace simdjson::builtin;
|
||||
|
||||
class simdjson_ondemand_unordered {
|
||||
struct simdjson_ondemand_unordered {
|
||||
ondemand::parser parser{};
|
||||
public:
|
||||
|
||||
bool run(const simdjson::padded_string &json, std::vector<point> &points) {
|
||||
auto doc = parser.iterate(json);
|
||||
for (ondemand::object coord : doc) {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
namespace large_random {
|
||||
|
||||
class yyjson {
|
||||
struct yyjson {
|
||||
simdjson_really_inline double get_double(yyjson_val *obj, std::string_view key) {
|
||||
yyjson_val *val = yyjson_obj_getn(obj, key.data(), key.length());
|
||||
if (!val) { throw "missing point field!"; }
|
||||
|
@ -24,7 +24,6 @@ class yyjson {
|
|||
}
|
||||
}
|
||||
|
||||
public:
|
||||
bool run(const simdjson::padded_string &json, std::vector<point> &points) {
|
||||
// Walk the document, parsing the tweets as we go
|
||||
yyjson_doc *doc = yyjson_read(json.data(), json.size(), 0);
|
||||
|
|
|
@ -8,8 +8,7 @@ namespace partial_tweets {
|
|||
|
||||
using namespace rapidjson;
|
||||
|
||||
template<int F>
|
||||
class rapidjson_base {
|
||||
struct rapidjson_base {
|
||||
Document doc{};
|
||||
|
||||
simdjson_really_inline std::string_view get_string_view(Value &object, std::string_view key) {
|
||||
|
@ -39,9 +38,7 @@ class rapidjson_base {
|
|||
return { get_uint64(field->value, "id"), get_string_view(field->value, "screen_name") };
|
||||
}
|
||||
|
||||
public:
|
||||
bool run(const padded_string &json, std::vector<tweet> &tweets) {
|
||||
auto &root = doc.Parse<F>(json.data());
|
||||
bool run(Document &root, std::vector<tweet> &tweets) {
|
||||
if (root.HasParseError() || !root.IsObject()) { return false; }
|
||||
auto statuses = root.FindMember("statuses");
|
||||
if (statuses == root.MemberEnd() || !statuses->value.IsArray()) { return false; }
|
||||
|
@ -62,8 +59,13 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class rapidjson : public rapidjson_base<kParseValidateEncodingFlag> {};
|
||||
BENCHMARK_TEMPLATE(partial_tweets, rapidjson);
|
||||
struct rapidjson : public rapidjson_base {
|
||||
bool run(const padded_string &json, std::vector<tweet> &tweets) {
|
||||
return rapidjson_base::run(doc.Parse<kParseValidateEncodingFlag>(json.data()), tweets);
|
||||
}
|
||||
};
|
||||
|
||||
BENCHMARK_TEMPLATE(partial_tweets, rapidjson);
|
||||
|
||||
} // namespace partial_tweets
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace partial_tweets {
|
|||
|
||||
using namespace simdjson;
|
||||
|
||||
class simdjson_dom {
|
||||
struct simdjson_dom {
|
||||
dom::parser parser{};
|
||||
|
||||
simdjson_really_inline uint64_t nullable_int(dom::element element) {
|
||||
|
@ -16,7 +16,6 @@ class simdjson_dom {
|
|||
return element;
|
||||
}
|
||||
|
||||
public:
|
||||
bool run(const padded_string &json, std::vector<tweet> &tweets) {
|
||||
for (dom::element tweet : parser.parse(json)["statuses"]) {
|
||||
auto user = tweet["user"];
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace partial_tweets {
|
|||
using namespace simdjson;
|
||||
using namespace simdjson::builtin;
|
||||
|
||||
class simdjson_ondemand {
|
||||
struct simdjson_ondemand {
|
||||
ondemand::parser parser{};
|
||||
|
||||
simdjson_really_inline uint64_t nullable_int(ondemand::value value) {
|
||||
|
@ -21,7 +21,6 @@ class simdjson_ondemand {
|
|||
return { user.find_field("id"), user.find_field("screen_name") };
|
||||
}
|
||||
|
||||
public:
|
||||
bool run(const padded_string &json, std::vector<tweet> &tweets) {
|
||||
// Walk the document, parsing the tweets as we go
|
||||
auto doc = parser.iterate(json);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
namespace partial_tweets {
|
||||
|
||||
class yyjson {
|
||||
struct yyjson {
|
||||
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());
|
||||
if (!yyjson_is_str(val)) { throw "field is not uint64 or null!"; }
|
||||
|
@ -30,7 +30,6 @@ class yyjson {
|
|||
return { get_uint64(user, "id"), get_string_view(user, "screen_name") };
|
||||
}
|
||||
|
||||
public:
|
||||
bool run(const padded_string &json, std::vector<tweet> &tweets) {
|
||||
// Walk the document, parsing the tweets as we go
|
||||
yyjson_doc *doc = yyjson_read(json.data(), json.size(), 0);
|
||||
|
|
Loading…
Reference in New Issue