mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-01-01 11:29:17 +00:00
All experimentation on the effect of JSON parser reuser.
Signed-off-by: Adrian Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
31c3a57485
commit
dcba8efc83
@ -6,11 +6,13 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
|
#ifdef JSON_PREFER_REUSE_OF_PARSER
|
||||||
#ifdef USE_JSONCPP_JSON
|
#ifdef USE_JSONCPP_JSON
|
||||||
std::unique_ptr<Json::CharReader> opcode_test_suite_t::m_parser;
|
std::unique_ptr<Json::CharReader> opcode_test_suite_t::m_parser;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_SIMDJSON_JSON
|
#ifdef USE_SIMDJSON_JSON
|
||||||
std::unique_ptr<simdjson::dom::parser> opcode_test_suite_t::m_parser;
|
simdjson::dom::parser opcode_test_suite_t::m_parser;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string opcode_test_suite_t::read(std::string path) {
|
std::string opcode_test_suite_t::read(std::string path) {
|
||||||
@ -50,11 +52,18 @@ void opcode_test_suite_t::load() {
|
|||||||
#ifdef USE_JSONCPP_JSON
|
#ifdef USE_JSONCPP_JSON
|
||||||
|
|
||||||
void opcode_test_suite_t::load() {
|
void opcode_test_suite_t::load() {
|
||||||
|
#ifdef JSON_PREFER_REUSE_OF_PARSER
|
||||||
if (m_parser == nullptr)
|
if (m_parser == nullptr)
|
||||||
m_parser.reset(Json::CharReaderBuilder().newCharReader());
|
m_parser.reset(Json::CharReaderBuilder().newCharReader());
|
||||||
const auto contents = read(path());
|
const auto contents = read(path());
|
||||||
if (!m_parser->parse(contents.data(), contents.data() + contents.size(), &m_raw, nullptr))
|
if (!m_parser->parse(contents.data(), contents.data() + contents.size(), &m_raw, nullptr))
|
||||||
throw std::runtime_error("Unable to parse tests");
|
throw std::runtime_error("Unable to parse tests");
|
||||||
|
#else
|
||||||
|
const auto contents = read(path());
|
||||||
|
std::unique_ptr<Json::CharReader> parser(Json::CharReaderBuilder().newCharReader());
|
||||||
|
if (!parser->parse(contents.data(), contents.data() + contents.size(), &m_raw, nullptr))
|
||||||
|
throw std::runtime_error("Unable to parse tests");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -62,10 +71,8 @@ void opcode_test_suite_t::load() {
|
|||||||
#ifdef USE_SIMDJSON_JSON
|
#ifdef USE_SIMDJSON_JSON
|
||||||
|
|
||||||
void opcode_test_suite_t::load() {
|
void opcode_test_suite_t::load() {
|
||||||
if (m_parser == nullptr)
|
|
||||||
m_parser = std::make_unique<simdjson::dom::parser>();
|
|
||||||
const auto contents = read(path());
|
const auto contents = read(path());
|
||||||
m_raw = m_parser->parse(contents);
|
m_raw = m_parser.parse(contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -21,11 +21,16 @@
|
|||||||
|
|
||||||
class opcode_test_suite_t final {
|
class opcode_test_suite_t final {
|
||||||
private:
|
private:
|
||||||
|
#ifdef JSON_PREFER_REUSE_OF_PARSER
|
||||||
#ifdef USE_JSONCPP_JSON
|
#ifdef USE_JSONCPP_JSON
|
||||||
static std::unique_ptr<Json::CharReader> m_parser;
|
static std::unique_ptr<Json::CharReader> m_parser;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_SIMDJSON_JSON
|
#ifdef USE_SIMDJSON_JSON
|
||||||
static std::unique_ptr<simdjson::dom::parser> m_parser;
|
// N.B.
|
||||||
|
// The parser must be kept for the lifetime of any parsed data.
|
||||||
|
// Therefore, it can only be used for one document at a time.
|
||||||
|
static simdjson::dom::parser m_parser;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[[nodiscard]] static std::string read(std::string path);
|
[[nodiscard]] static std::string read(std::string path);
|
||||||
@ -42,6 +47,10 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
#ifdef USE_SIMDJSON_JSON
|
#ifdef USE_SIMDJSON_JSON
|
||||||
simdjson::dom::element m_raw;
|
simdjson::dom::element m_raw;
|
||||||
|
#ifndef JSON_PREFER_REUSE_OF_PARSER
|
||||||
|
// N.B. The parser must be kept for the lifetime of any parsed data.
|
||||||
|
simdjson::dom::parser m_parser;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -27,10 +27,12 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_JSONCPP_JSON
|
#ifdef USE_JSONCPP_JSON
|
||||||
|
# define JSON_PREFER_REUSE_OF_PARSER
|
||||||
# include <json/json.h>
|
# include <json/json.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_SIMDJSON_JSON
|
#ifdef USE_SIMDJSON_JSON
|
||||||
# define JSON_PREFER_PASS_BY_VALUE
|
# define JSON_PREFER_PASS_BY_VALUE
|
||||||
|
# define JSON_PREFER_REUSE_OF_PARSER
|
||||||
# include "simdjson/simdjson.h"
|
# include "simdjson/simdjson.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -35,7 +35,7 @@ int main() {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef USE_SIMDJSON_JSON
|
#ifdef USE_SIMDJSON_JSON
|
||||||
assert(opcode.raw().is_array());
|
assert(opcode.raw().is_array());
|
||||||
const auto& opcode_test_array = opcode.raw().get_array();
|
const auto opcode_test_array = opcode.raw().get_array();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool opcode_bad = false;
|
bool opcode_bad = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user