mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-01-16 19:32:32 +00:00
Split load/parse of opcode tests.
Signed-off-by: Adrian Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
dcba8efc83
commit
4892ea95d3
@ -26,6 +26,10 @@ std::string opcode_test_suite_t::read(std::string path) {
|
|||||||
opcode_test_suite_t::opcode_test_suite_t(std::string path)
|
opcode_test_suite_t::opcode_test_suite_t(std::string path)
|
||||||
: m_path(path) {}
|
: m_path(path) {}
|
||||||
|
|
||||||
|
void opcode_test_suite_t::load() {
|
||||||
|
m_contents = read(path());
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_BOOST_JSON
|
#ifdef USE_BOOST_JSON
|
||||||
|
|
||||||
const boost::json::array& opcode_test_suite_t::get_array() const noexcept {
|
const boost::json::array& opcode_test_suite_t::get_array() const noexcept {
|
||||||
@ -33,46 +37,47 @@ const boost::json::array& opcode_test_suite_t::get_array() const noexcept {
|
|||||||
return raw().get_array();
|
return raw().get_array();
|
||||||
}
|
}
|
||||||
|
|
||||||
void opcode_test_suite_t::load() {
|
void opcode_test_suite_t::parse() {
|
||||||
const auto contents = read(path());
|
m_raw = boost::json::parse(m_contents);
|
||||||
m_raw = boost::json::parse(contents);
|
m_contents.clear();
|
||||||
}
|
m_contents.shrink_to_fit();}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_NLOHMANN_JSON
|
#ifdef USE_NLOHMANN_JSON
|
||||||
|
|
||||||
void opcode_test_suite_t::load() {
|
void opcode_test_suite_t::parse() {
|
||||||
const auto contents = read(path());
|
m_raw = nlohmann::json::parse(m_contents);
|
||||||
m_raw = nlohmann::json::parse(contents);
|
m_contents.clear();
|
||||||
}
|
m_contents.shrink_to_fit();}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_JSONCPP_JSON
|
#ifdef USE_JSONCPP_JSON
|
||||||
|
|
||||||
void opcode_test_suite_t::load() {
|
void opcode_test_suite_t::parse() {
|
||||||
#ifdef JSON_PREFER_REUSE_OF_PARSER
|
#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());
|
if (!m_parser->parse(m_contents.data(), m_contents.data() + m_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
|
#else
|
||||||
const auto contents = read(path());
|
|
||||||
std::unique_ptr<Json::CharReader> parser(Json::CharReaderBuilder().newCharReader());
|
std::unique_ptr<Json::CharReader> parser(Json::CharReaderBuilder().newCharReader());
|
||||||
if (!parser->parse(contents.data(), contents.data() + contents.size(), &m_raw, nullptr))
|
if (!parser->parse(m_contents.data(), m_contents.data() + m_contents.size(), &m_raw, nullptr))
|
||||||
throw std::runtime_error("Unable to parse tests");
|
throw std::runtime_error("Unable to parse tests");
|
||||||
#endif
|
#endif
|
||||||
|
m_contents.clear();
|
||||||
|
m_contents.shrink_to_fit();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_SIMDJSON_JSON
|
#ifdef USE_SIMDJSON_JSON
|
||||||
|
|
||||||
void opcode_test_suite_t::load() {
|
void opcode_test_suite_t::parse() {
|
||||||
const auto contents = read(path());
|
m_raw = m_parser.parse(m_contents);
|
||||||
m_raw = m_parser.parse(contents);
|
m_contents.clear();
|
||||||
|
m_contents.shrink_to_fit();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,6 +36,7 @@ private:
|
|||||||
[[nodiscard]] static std::string read(std::string path);
|
[[nodiscard]] static std::string read(std::string path);
|
||||||
|
|
||||||
std::string m_path;
|
std::string m_path;
|
||||||
|
std::string m_contents;
|
||||||
#ifdef USE_BOOST_JSON
|
#ifdef USE_BOOST_JSON
|
||||||
boost::json::value m_raw;
|
boost::json::value m_raw;
|
||||||
#endif
|
#endif
|
||||||
@ -68,5 +69,6 @@ public:
|
|||||||
[[nodiscard]] const boost::json::array& get_array() const noexcept;
|
[[nodiscard]] const boost::json::array& get_array() const noexcept;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void load();
|
void load(); // Reads into contents
|
||||||
|
void parse(); // Parse the contents
|
||||||
};
|
};
|
||||||
|
@ -18,11 +18,10 @@ int main() {
|
|||||||
|
|
||||||
const auto path = entry.path();
|
const auto path = entry.path();
|
||||||
|
|
||||||
const auto filename = path.filename();
|
std::cout << "Processing: " << path.filename() << "\n";
|
||||||
std::cout << "Processing: " << filename << "\n";
|
|
||||||
|
|
||||||
opcode_test_suite_t opcode(path.string());
|
opcode_test_suite_t opcode(path.string());
|
||||||
opcode.load();
|
opcode.load();
|
||||||
|
opcode.parse();
|
||||||
|
|
||||||
#ifdef USE_BOOST_JSON
|
#ifdef USE_BOOST_JSON
|
||||||
const auto& opcode_test_array = opcode.get_array();
|
const auto& opcode_test_array = opcode.get_array();
|
||||||
@ -59,10 +58,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto finish_time = std::chrono::steady_clock::now();
|
const auto finish_time = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
const auto elapsed_time = finish_time - start_time;
|
const auto elapsed_time = finish_time - start_time;
|
||||||
|
|
||||||
const auto seconds = std::chrono::duration_cast<std::chrono::duration<double>>(elapsed_time).count();
|
const auto seconds = std::chrono::duration_cast<std::chrono::duration<double>>(elapsed_time).count();
|
||||||
|
|
||||||
std::cout << "Elapsed time: " << seconds << " seconds" << std::endl;
|
std::cout << "Elapsed time: " << seconds << " seconds" << std::endl;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user