2021-01-05 07:22:35 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifdef SIMDJSON_COMPETITION_RAPIDJSON
|
|
|
|
|
|
|
|
#include "large_random.h"
|
|
|
|
|
|
|
|
namespace large_random {
|
|
|
|
|
|
|
|
using namespace rapidjson;
|
|
|
|
|
2021-01-05 12:20:24 +08:00
|
|
|
struct rapidjson_base {
|
2021-01-05 07:22:35 +08:00
|
|
|
Document doc;
|
|
|
|
|
|
|
|
simdjson_really_inline double get_double(Value &object, std::string_view key) {
|
|
|
|
auto field = object.FindMember(key.data());
|
|
|
|
if (field == object.MemberEnd()) { throw "Missing double field"; }
|
|
|
|
if (!field->value.IsNumber()) { throw "Field is not double"; }
|
|
|
|
return field->value.GetDouble();
|
|
|
|
}
|
|
|
|
|
2021-01-05 12:20:24 +08:00
|
|
|
bool run(Document &coords, std::vector<point> &points) {
|
2021-01-05 07:22:35 +08:00
|
|
|
if (coords.HasParseError()) { return false; }
|
|
|
|
if (!coords.IsArray()) { return false; }
|
|
|
|
for (auto &coord : coords.GetArray()) {
|
|
|
|
if (!coord.IsObject()) { return false; }
|
|
|
|
points.emplace_back(point{get_double(coord, "x"), get_double(coord, "y"), get_double(coord, "z")});
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-05 12:20:24 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-05 07:22:35 +08:00
|
|
|
BENCHMARK_TEMPLATE(large_random, rapidjson);
|
|
|
|
BENCHMARK_TEMPLATE(large_random, rapidjson_lossless);
|
|
|
|
|
|
|
|
} // namespace large_random
|
|
|
|
|
|
|
|
#endif // SIMDJSON_COMPETITION_RAPIDJSON
|