From b70f24a581a79b2689db9ba8f7462d5b8e04c2f6 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Wed, 20 Oct 2021 21:44:43 +0100 Subject: [PATCH] Draw an end to my json experimentations. simdjson is king. long live simdjson! Signed-off-by: Adrian Conlon --- M6502/HarteTest_6502/HarteTest_6502.vcxproj | 35 +----- .../HarteTest_6502.vcxproj.filters | 75 ------------ M6502/HarteTest_6502/byte_t.cpp | 110 ------------------ M6502/HarteTest_6502/byte_t.h | 91 +-------------- M6502/HarteTest_6502/cycle_t.cpp | 62 ---------- M6502/HarteTest_6502/cycle_t.h | 39 +------ M6502/HarteTest_6502/cycles_t.cpp | 51 -------- M6502/HarteTest_6502/cycles_t.h | 40 +------ M6502/HarteTest_6502/opcode_test_suite_t.cpp | 62 ---------- M6502/HarteTest_6502/opcode_test_suite_t.h | 51 +------- M6502/HarteTest_6502/packages.config | 4 - M6502/HarteTest_6502/ram_t.cpp | 51 -------- M6502/HarteTest_6502/ram_t.h | 39 +------ M6502/HarteTest_6502/state_t.cpp | 60 ---------- M6502/HarteTest_6502/state_t.h | 39 +------ M6502/HarteTest_6502/stdafx.h | 41 +------ M6502/HarteTest_6502/test_t.cpp | 47 -------- M6502/HarteTest_6502/test_t.h | 40 +------ M6502/HarteTest_6502/tests.cpp | 20 +--- 19 files changed, 10 insertions(+), 947 deletions(-) delete mode 100644 M6502/HarteTest_6502/packages.config diff --git a/M6502/HarteTest_6502/HarteTest_6502.vcxproj b/M6502/HarteTest_6502/HarteTest_6502.vcxproj index 37447ee..37c06b2 100644 --- a/M6502/HarteTest_6502/HarteTest_6502.vcxproj +++ b/M6502/HarteTest_6502/HarteTest_6502.vcxproj @@ -187,30 +187,8 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -225,17 +203,6 @@ {d8726a1b-bbfe-47ef-9860-26b90140ba66} - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + \ No newline at end of file diff --git a/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters b/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters index 2b1cec4..4e68e4a 100644 --- a/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters +++ b/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters @@ -9,15 +9,9 @@ {93995380-89BD-4b04-88EB-625FBE52EBFB} h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - {1b676a2e-dff7-46aa-b021-f4319b0419d7} - {92d132eb-117f-4f61-bad7-de75aa3cb6cf} - - {4f98c949-9b35-4a51-b579-8551931bd9c2} - @@ -70,9 +64,6 @@ Header Files - - Header Files\nlohmann - Header Files\simdjson @@ -85,74 +76,8 @@ Header Files - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - - - Header Files\rapidjson - Header Files - - - \ No newline at end of file diff --git a/M6502/HarteTest_6502/byte_t.cpp b/M6502/HarteTest_6502/byte_t.cpp index fcb9d11..e47a2d8 100644 --- a/M6502/HarteTest_6502/byte_t.cpp +++ b/M6502/HarteTest_6502/byte_t.cpp @@ -1,118 +1,8 @@ #include "stdafx.h" #include "byte_t.h" -#include - -#ifdef USE_SIMDJSON_JSON - byte_t::byte_t(simdjson::dom::element input) noexcept : byte_t(input.get_array()) {} -#ifdef JSON_ACCESS_DATA_VIA_OBJECT - byte_t::byte_t(simdjson::dom::array input) noexcept : m_raw(input) {} - -#else // JSON_ACCESS_DATA_VIA_OBJECT - -#ifdef JSON_PREFER_ITERATOR_TO_INDEX - -byte_t::byte_t(simdjson::dom::array input) noexcept { - assert(input.size() == 2); - auto iterator = input.begin(); - m_address = (uint16_t)(int64_t)*iterator; - m_value = (uint8_t)(int64_t)*++iterator; -} - -#else // JSON_PREFER_ITERATOR_TO_INDEX - -byte_t::byte_t(simdjson::dom::array input) noexcept -: m_address((uint16_t)(int64_t)input.at(0)), - m_value((uint8_t)(int64_t)input.at(1)) { - assert(input.size() == 2); -} - -#endif // JSON_PREFER_ITERATOR_TO_INDEX - -#endif // JSON_ACCESS_DATA_VIA_OBJECT - -#endif // USE_SIMDJSON_JSON - -#ifdef USE_RAPIDJSON_JSON - -#ifdef JSON_ACCESS_DATA_VIA_OBJECT - -byte_t::byte_t(const rapidjson::Value& input) -: m_raw(input) {} - -#else - -byte_t::byte_t(const rapidjson::Value& input) -: m_address((uint16_t)input[0].GetInt64()), - m_value((uint8_t)input[1].GetInt64()) {} - -#endif - -#endif - -#ifdef USE_BOOST_JSON - -byte_t::byte_t(const boost::json::value& input) noexcept -: byte_t(input.get_array()) {} - - -#ifdef JSON_ACCESS_DATA_VIA_OBJECT - -byte_t::byte_t(const boost::json::array& input) noexcept -: m_raw(input) {} - -#else - -byte_t::byte_t(const boost::json::array& input) noexcept -: m_address((uint16_t)input[0].get_int64()), - m_value((uint8_t)input[1].get_int64()) { - assert(input.size() == 2); -} - -#endif - -#endif - -#ifdef USE_NLOHMANN_JSON - -#ifdef JSON_ACCESS_DATA_VIA_OBJECT - -byte_t::byte_t(const nlohmann::json& input) noexcept -: m_raw(input) {} - -#else - -byte_t::byte_t(const nlohmann::json& input) noexcept -: m_address(input[0].get()), - m_value(input[1].get()) { - assert(input.size() == 2); -} - -#endif - - -#endif - -#ifdef USE_JSONCPP_JSON - -#ifdef JSON_ACCESS_DATA_VIA_OBJECT - -byte_t::byte_t(const Json::Value& input) -: m_raw(input) {} - -#else - -byte_t::byte_t(const Json::Value& input) -: m_address((uint16_t)input[0].asInt64()), - m_value((uint8_t)input[1].asInt64()) { - assert(input.size() == 2); -} - -#endif - -#endif diff --git a/M6502/HarteTest_6502/byte_t.h b/M6502/HarteTest_6502/byte_t.h index 44dd9ba..668c919 100644 --- a/M6502/HarteTest_6502/byte_t.h +++ b/M6502/HarteTest_6502/byte_t.h @@ -2,105 +2,16 @@ #include -#ifdef USE_SIMDJSON_JSON -# include "simdjson/simdjson.h" -#endif - -#ifdef USE_RAPIDJSON_JSON -# include "rapidjson/document.h" -#endif - -#ifdef USE_BOOST_JSON -# include -#endif - -#ifdef USE_NLOHMANN_JSON -# include "nlohmann/json.hpp" -#endif - -#ifdef USE_JSONCPP_JSON -# include -#endif +#include "simdjson/simdjson.h" class byte_t final { private: - -#ifdef JSON_ACCESS_DATA_VIA_OBJECT - -#ifdef USE_SIMDJSON_JSON simdjson::dom::array m_raw; -#endif - -#ifdef USE_RAPIDJSON_JSON - const rapidjson::Value& m_raw; -#endif - -#ifdef USE_BOOST_JSON - const boost::json::array& m_raw; -#endif - -#ifdef USE_NLOHMANN_JSON - const nlohmann::json& m_raw; -#endif - -#ifdef USE_JSONCPP_JSON - const Json::Value& m_raw; -#endif - -#else - - uint16_t m_address = 0xffff; - uint8_t m_value = 0xff; - -#endif public: - -#ifdef USE_SIMDJSON_JSON byte_t(simdjson::dom::element input) noexcept; byte_t(simdjson::dom::array input) noexcept; -#endif -#ifdef USE_RAPIDJSON_JSON - byte_t(const rapidjson::Value& input); -#endif - -#ifdef USE_BOOST_JSON - byte_t(const boost::json::value& input) noexcept; - byte_t(const boost::json::array& input) noexcept; -#endif - -#ifdef USE_NLOHMANN_JSON - byte_t(const nlohmann::json& input) noexcept; -#endif - -#ifdef USE_JSONCPP_JSON - byte_t(const Json::Value& input); -#endif - -#ifdef JSON_ACCESS_DATA_VIA_OBJECT -#ifdef USE_SIMDJSON_JSON [[nodiscard]] auto address() const noexcept { return (uint16_t)(int64_t)*m_raw.begin(); } [[nodiscard]] auto value() const noexcept { return (uint8_t)(int64_t)m_raw.at(1); } -#endif -#ifdef USE_RAPIDJSON_JSON - [[nodiscard]] auto address() const noexcept { return (uint16_t)m_raw[0].GetInt64(); } - [[nodiscard]] auto value() const noexcept { return (uint8_t)m_raw[1].GetInt64(); } -#endif -#ifdef USE_BOOST_JSON - [[nodiscard]] auto address() const noexcept { return (uint16_t)m_raw[0].get_int64(); } - [[nodiscard]] auto value() const noexcept { return (uint8_t)m_raw[1].get_int64(); } -#endif -#ifdef USE_NLOHMANN_JSON - [[nodiscard]] auto address() const noexcept { return m_raw[0].get(); } - [[nodiscard]] auto value() const noexcept { return m_raw[1].get(); } -#endif -#ifdef USE_JSONCPP_JSON - [[nodiscard]] auto address() const noexcept { return (uint16_t)m_raw[0].asInt64(); } - [[nodiscard]] auto value() const noexcept { return (uint8_t)m_raw[1].asInt64(); } -#endif -#else - [[nodiscard]] constexpr auto address() const noexcept { return m_address; } - [[nodiscard]] constexpr auto value() const noexcept { return m_value; } -#endif }; diff --git a/M6502/HarteTest_6502/cycle_t.cpp b/M6502/HarteTest_6502/cycle_t.cpp index 66160e2..c1e6183 100644 --- a/M6502/HarteTest_6502/cycle_t.cpp +++ b/M6502/HarteTest_6502/cycle_t.cpp @@ -24,13 +24,9 @@ cycle_t::cycle_t(uint16_t address, uint8_t value, action_t action) noexcept m_value(value), m_action(action) {} -#ifdef USE_SIMDJSON_JSON - cycle_t::cycle_t(simdjson::dom::element input) noexcept : cycle_t(input.get_array()) {} -#ifdef JSON_PREFER_ITERATOR_TO_INDEX - cycle_t::cycle_t(simdjson::dom::array input) noexcept { assert(input.size() == 3); auto iterator = input.begin(); @@ -38,61 +34,3 @@ cycle_t::cycle_t(simdjson::dom::array input) noexcept { m_value = (uint8_t)(int64_t)*++iterator; m_action = to_action((std::string)*++iterator); } - -#else - -cycle_t::cycle_t(simdjson::dom::array input) noexcept -: m_address((uint16_t)(int64_t)input.at(0)), - m_value((uint8_t)(int64_t)input.at(1)), - m_action(to_action((std::string)input.at(2))) { - assert(input.size() == 3); -} - -#endif - -#endif - -#ifdef USE_RAPIDJSON_JSON - -cycle_t::cycle_t(const rapidjson::Value& input) -: m_address((uint16_t)input[0].GetInt64()), - m_value((uint8_t)input[1].GetInt64()), - m_action(to_action(input[2].GetString())) {} - -#endif - -#ifdef USE_BOOST_JSON - -cycle_t::cycle_t(const boost::json::value& input) noexcept -: cycle_t(input.get_array()) {} - -cycle_t::cycle_t(const boost::json::array& input) noexcept -: m_address((uint16_t)input[0].get_int64()), - m_value((uint8_t)input[1].get_int64()), - m_action(to_action((std::string)input[2].get_string())) { - assert(input.size() == 3); -}; - -#endif - -#ifdef USE_NLOHMANN_JSON - -cycle_t::cycle_t(const nlohmann::json& input) noexcept -: m_address(input[0].get()), - m_value(input[1].get()), - m_action(to_action(input[2].get())) { - assert(input.size() == 3); -} - -#endif - -#ifdef USE_JSONCPP_JSON - -cycle_t::cycle_t(const Json::Value& input) -: m_address((uint16_t)input[0].asInt64()), - m_value((uint8_t)input[1].asInt64()), - m_action(to_action(input[2].asString())) { - assert(input.size() == 3); -} - -#endif diff --git a/M6502/HarteTest_6502/cycle_t.h b/M6502/HarteTest_6502/cycle_t.h index 90eba8b..1a3a5fc 100644 --- a/M6502/HarteTest_6502/cycle_t.h +++ b/M6502/HarteTest_6502/cycle_t.h @@ -3,25 +3,7 @@ #include #include -#ifdef USE_SIMDJSON_JSON -# include "simdjson/simdjson.h" -#endif - -#ifdef USE_RAPIDJSON_JSON -# include "rapidjson/document.h" -#endif - -#ifdef USE_BOOST_JSON -# include -#endif - -#ifdef USE_NLOHMANN_JSON -# include "nlohmann/json.hpp" -#endif - -#ifdef USE_JSONCPP_JSON -# include -#endif +#include "simdjson/simdjson.h" class cycle_t final { public: @@ -38,27 +20,8 @@ public: cycle_t(uint16_t address, uint8_t value, action_t action) noexcept; -#ifdef USE_SIMDJSON_JSON cycle_t(simdjson::dom::element input) noexcept; cycle_t(simdjson::dom::array input) noexcept; -#endif - -#ifdef USE_RAPIDJSON_JSON - cycle_t(const rapidjson::Value& input); -#endif - -#ifdef USE_BOOST_JSON - cycle_t(const boost::json::value& input) noexcept; - cycle_t(const boost::json::array& input) noexcept; -#endif - -#ifdef USE_NLOHMANN_JSON - cycle_t(const nlohmann::json& input) noexcept; -#endif - -#ifdef USE_JSONCPP_JSON - cycle_t(const Json::Value& input); -#endif [[nodiscard]] constexpr auto address() const noexcept { return m_address; } [[nodiscard]] constexpr auto value() const noexcept { return m_value; } diff --git a/M6502/HarteTest_6502/cycles_t.cpp b/M6502/HarteTest_6502/cycles_t.cpp index d689a60..24e2091 100644 --- a/M6502/HarteTest_6502/cycles_t.cpp +++ b/M6502/HarteTest_6502/cycles_t.cpp @@ -10,60 +10,9 @@ void cycles_t::add(const cycle_t& cycle) { m_cycles.push_back(cycle); } -#ifdef USE_SIMDJSON_JSON - cycles_t::cycles_t(simdjson::dom::array input) { assert(m_cycles.empty()); m_cycles.reserve(input.size()); for (const auto& entry : input) add(entry); } - -#endif - -#ifdef USE_RAPIDJSON_JSON - -cycles_t::cycles_t(const rapidjson::Value& input) { - assert(m_cycles.empty()); - m_cycles.reserve(input.Size()); - for (const auto& entry : input.GetArray()) - add(entry); -} - -#endif - -#ifdef USE_BOOST_JSON - -cycles_t::cycles_t(const boost::json::value& input) -: cycles_t(input.get_array()) {} - -cycles_t::cycles_t(const boost::json::array& input) { - assert(m_cycles.empty()); - m_cycles.reserve(input.size()); - for (const auto& entry : input) - add(entry); -} - -#endif - -#ifdef USE_NLOHMANN_JSON - -cycles_t::cycles_t(const nlohmann::json& input) { - assert(m_cycles.empty()); - m_cycles.reserve(input.size()); - for (const auto& entry : input) - add(entry); -} - -#endif - -#ifdef USE_JSONCPP_JSON - -cycles_t::cycles_t(const Json::Value& input) { - assert(m_cycles.empty()); - m_cycles.reserve(input.size()); - for (const auto& entry : input) - add(entry); -} - -#endif diff --git a/M6502/HarteTest_6502/cycles_t.h b/M6502/HarteTest_6502/cycles_t.h index 882f47f..a290236 100644 --- a/M6502/HarteTest_6502/cycles_t.h +++ b/M6502/HarteTest_6502/cycles_t.h @@ -2,25 +2,7 @@ #include -#ifdef USE_SIMDJSON_JSON -# include "simdjson/simdjson.h" -#endif - -#ifdef USE_RAPIDJSON_JSON -# include "rapidjson/document.h" -#endif - -#ifdef USE_BOOST_JSON -# include -#endif - -#ifdef USE_NLOHMANN_JSON -# include "nlohmann/json.hpp" -#endif - -#ifdef USE_JSONCPP_JSON -# include -#endif +#include "simdjson/simdjson.h" #include "cycle_t.h" @@ -30,27 +12,7 @@ private: public: cycles_t(size_t reserved = 10); - -#ifdef USE_SIMDJSON_JSON cycles_t(simdjson::dom::array input); -#endif - -#ifdef USE_RAPIDJSON_JSON - cycles_t(const rapidjson::Value& input); -#endif - -#ifdef USE_BOOST_JSON - cycles_t(const boost::json::value& input); - cycles_t(const boost::json::array& input); -#endif - -#ifdef USE_NLOHMANN_JSON - cycles_t(const nlohmann::json& input); -#endif - -#ifdef USE_JSONCPP_JSON - cycles_t(const Json::Value& input); -#endif void add(const cycle_t& cycle); diff --git a/M6502/HarteTest_6502/opcode_test_suite_t.cpp b/M6502/HarteTest_6502/opcode_test_suite_t.cpp index 4d9df97..51c5873 100644 --- a/M6502/HarteTest_6502/opcode_test_suite_t.cpp +++ b/M6502/HarteTest_6502/opcode_test_suite_t.cpp @@ -6,14 +6,7 @@ #include #include -#ifdef JSON_PREFER_REUSE_OF_PARSER -#ifdef USE_JSONCPP_JSON -std::unique_ptr opcode_test_suite_t::m_parser; -#endif -#ifdef USE_SIMDJSON_JSON simdjson::dom::parser opcode_test_suite_t::m_parser; -#endif -#endif std::string opcode_test_suite_t::read(std::string path) { std::ifstream file(path, std::ios::in | std::ios::binary); @@ -30,63 +23,8 @@ void opcode_test_suite_t::load() { m_contents = read(path()); } -#ifdef USE_BOOST_JSON - -void opcode_test_suite_t::parse() { - m_raw = boost::json::parse(m_contents); - m_contents.clear(); - m_contents.shrink_to_fit();} - -#endif - -#ifdef USE_NLOHMANN_JSON - -void opcode_test_suite_t::parse() { - m_raw = nlohmann::json::parse(m_contents); - m_contents.clear(); - m_contents.shrink_to_fit();} - -#endif - -#ifdef USE_JSONCPP_JSON - -void opcode_test_suite_t::parse() { -#ifdef JSON_PREFER_REUSE_OF_PARSER - if (m_parser == nullptr) - m_parser.reset(Json::CharReaderBuilder().newCharReader()); - if (!m_parser->parse(m_contents.data(), m_contents.data() + m_contents.size(), &m_raw, nullptr)) - throw std::runtime_error("Unable to parse tests"); -#else - std::unique_ptr parser(Json::CharReaderBuilder().newCharReader()); - if (!parser->parse(m_contents.data(), m_contents.data() + m_contents.size(), &m_raw, nullptr)) - throw std::runtime_error("Unable to parse tests"); -#endif - m_contents.clear(); - m_contents.shrink_to_fit(); -} - -#endif - -#ifdef USE_SIMDJSON_JSON - void opcode_test_suite_t::parse() { m_raw = m_parser.parse(m_contents); m_contents.clear(); m_contents.shrink_to_fit(); } - -#endif - -#ifdef USE_RAPIDJSON_JSON - -void opcode_test_suite_t::parse() { -#ifdef JSON_INSITU_PARSE - m_raw.ParseInsitu((char*)m_contents.c_str()); -#else - m_raw.Parse(m_contents); - m_contents.clear(); - m_contents.shrink_to_fit(); -#endif -} - -#endif diff --git a/M6502/HarteTest_6502/opcode_test_suite_t.h b/M6502/HarteTest_6502/opcode_test_suite_t.h index c239941..5fa7d63 100644 --- a/M6502/HarteTest_6502/opcode_test_suite_t.h +++ b/M6502/HarteTest_6502/opcode_test_suite_t.h @@ -2,75 +2,26 @@ #include -#ifdef USE_BOOST_JSON -# include -#endif - -#ifdef USE_RAPIDJSON_JSON -# include "rapidjson/document.h" -#endif - -#ifdef USE_NLOHMANN_JSON -# include "nlohmann/json.hpp" -#endif - -#ifdef USE_JSONCPP_JSON -# include -# include -#endif - -#ifdef USE_SIMDJSON_JSON -# include "simdjson/simdjson.h" -#endif +#include "simdjson/simdjson.h" class opcode_test_suite_t final { private: -#ifdef JSON_PREFER_REUSE_OF_PARSER -#ifdef USE_JSONCPP_JSON - static std::unique_ptr m_parser; -#endif -#ifdef USE_SIMDJSON_JSON // 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 [[nodiscard]] static std::string read(std::string path); std::string m_path; std::string m_contents; -#ifdef USE_BOOST_JSON - boost::json::value m_raw; -#endif -#ifdef USE_RAPIDJSON_JSON - rapidjson::Document m_raw; -#endif -#ifdef USE_NLOHMANN_JSON - nlohmann::json m_raw; -#endif -#ifdef USE_JSONCPP_JSON - Json::Value m_raw; -#endif -#ifdef USE_SIMDJSON_JSON 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 public: opcode_test_suite_t(std::string path); [[nodiscard]] constexpr const auto& path() const noexcept { return m_path; } - -#ifdef JSON_PREFER_PASS_BY_VALUE [[nodiscard]] const auto raw() const noexcept { return m_raw; } -#else - [[nodiscard]] constexpr const auto& raw() const noexcept { return m_raw; } -#endif void load(); // Reads into contents void parse(); // Parse the contents diff --git a/M6502/HarteTest_6502/packages.config b/M6502/HarteTest_6502/packages.config deleted file mode 100644 index e4d3279..0000000 --- a/M6502/HarteTest_6502/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/M6502/HarteTest_6502/ram_t.cpp b/M6502/HarteTest_6502/ram_t.cpp index 5aaa62c..0e89763 100644 --- a/M6502/HarteTest_6502/ram_t.cpp +++ b/M6502/HarteTest_6502/ram_t.cpp @@ -6,60 +6,9 @@ void ram_t::add(byte_t byte) { m_bytes.push_back(byte); } -#ifdef USE_SIMDJSON_JSON - ram_t::ram_t(simdjson::dom::array input) { assert(m_bytes.empty()); m_bytes.reserve(input.size()); for (auto entry : input) add(entry); } - -#endif - -#ifdef USE_RAPIDJSON_JSON - -ram_t::ram_t(const rapidjson::Value& input) { - assert(m_bytes.empty()); - m_bytes.reserve(input.Size()); - for (const auto& entry : input.GetArray()) - add(entry); -} - -#endif - -#ifdef USE_BOOST_JSON - -ram_t::ram_t(const boost::json::array& input) { - assert(m_bytes.empty()); - m_bytes.reserve(input.size()); - for (const auto& entry : input) - add(entry); -} - -ram_t::ram_t(const boost::json::value& input) -: ram_t(input.get_array()) {} - -#endif - -#ifdef USE_NLOHMANN_JSON - -ram_t::ram_t(const nlohmann::json& input) { - assert(m_bytes.empty()); - m_bytes.reserve(input.size()); - for (const auto& entry : input) - add(entry); -} - -#endif - -#ifdef USE_JSONCPP_JSON - -ram_t::ram_t(const Json::Value& input) { - assert(m_bytes.empty()); - m_bytes.reserve(input.size()); - for (const auto& entry : input) - add(entry); -} - -#endif diff --git a/M6502/HarteTest_6502/ram_t.h b/M6502/HarteTest_6502/ram_t.h index 8f60aaa..4885b58 100644 --- a/M6502/HarteTest_6502/ram_t.h +++ b/M6502/HarteTest_6502/ram_t.h @@ -3,25 +3,7 @@ #include #include -#ifdef USE_SIMDJSON_JSON -# include "simdjson/simdjson.h" -#endif - -#ifdef USE_RAPIDJSON_JSON -# include "rapidjson/document.h" -#endif - -#ifdef USE_BOOST_JSON -# include -#endif - -#ifdef USE_NLOHMANN_JSON -# include "nlohmann/json.hpp" -#endif - -#ifdef USE_JSONCPP_JSON -# include -#endif +#include "simdjson/simdjson.h" #include "byte_t.h" @@ -30,26 +12,7 @@ private: std::vector m_bytes; public: -#ifdef USE_SIMDJSON_JSON ram_t(simdjson::dom::array input); -#endif - -#ifdef USE_RAPIDJSON_JSON - ram_t(const rapidjson::Value& input); -#endif - -#ifdef USE_BOOST_JSON - ram_t(const boost::json::value& input); - ram_t(const boost::json::array& input); -#endif - -#ifdef USE_NLOHMANN_JSON - ram_t(const nlohmann::json& input); -#endif - -#ifdef USE_JSONCPP_JSON - ram_t(const Json::Value& input); -#endif void add(byte_t byte); diff --git a/M6502/HarteTest_6502/state_t.cpp b/M6502/HarteTest_6502/state_t.cpp index f499d1c..c8d0e4b 100644 --- a/M6502/HarteTest_6502/state_t.cpp +++ b/M6502/HarteTest_6502/state_t.cpp @@ -1,8 +1,5 @@ #include "stdafx.h" #include "state_t.h" -#include - -#ifdef USE_SIMDJSON_JSON state_t::state_t(const simdjson::dom::element serialised) : m_pc((uint16_t)(int64_t)serialised["pc"]), @@ -12,60 +9,3 @@ state_t::state_t(const simdjson::dom::element serialised) m_y((uint8_t)(int64_t)serialised["y"]), m_p((uint8_t)(int64_t)serialised["p"]), m_ram(serialised["ram"].get_array()) {} - -#endif - -#ifdef USE_RAPIDJSON_JSON - -state_t::state_t(const rapidjson::Value& serialised) -: m_pc((uint16_t)serialised["pc"].GetInt64()), - m_s((uint8_t)serialised["s"].GetInt64()), - m_a((uint8_t)serialised["a"].GetInt64()), - m_x((uint8_t)serialised["x"].GetInt64()), - m_y((uint8_t)serialised["y"].GetInt64()), - m_p((uint8_t)serialised["p"].GetInt64()), - m_ram(serialised["ram"]) {} - -#endif - -#ifdef USE_BOOST_JSON - -state_t::state_t(const boost::json::object& serialised) -: m_pc((uint16_t)serialised.at("pc").get_int64()), - m_s((uint8_t)serialised.at("s").get_int64()), - m_a((uint8_t)serialised.at("a").get_int64()), - m_x((uint8_t)serialised.at("x").get_int64()), - m_y((uint8_t)serialised.at("y").get_int64()), - m_p((uint8_t)serialised.at("p").get_int64()), - m_ram(serialised.at("ram")) {} - -state_t::state_t(const boost::json::value& serialised) -: state_t(serialised.as_object()) {} - -#endif - -#ifdef USE_NLOHMANN_JSON - -state_t::state_t(const nlohmann::json& serialised) -: m_pc(serialised["pc"].get()), - m_s(serialised["s"].get()), - m_a(serialised["a"].get()), - m_x(serialised["x"].get()), - m_y(serialised["y"].get()), - m_p(serialised["p"].get()), - m_ram(serialised["ram"]) {} - -#endif - -#ifdef USE_JSONCPP_JSON - -state_t::state_t(const Json::Value& serialised) -: m_pc((uint16_t)serialised["pc"].asInt64()), - m_s((uint8_t)serialised["s"].asInt64()), - m_a((uint8_t)serialised["a"].asInt64()), - m_x((uint8_t)serialised["x"].asInt64()), - m_y((uint8_t)serialised["y"].asInt64()), - m_p((uint8_t)serialised["p"].asInt64()), - m_ram(serialised["ram"]) {} - -#endif diff --git a/M6502/HarteTest_6502/state_t.h b/M6502/HarteTest_6502/state_t.h index dc6f055..262c115 100644 --- a/M6502/HarteTest_6502/state_t.h +++ b/M6502/HarteTest_6502/state_t.h @@ -2,25 +2,7 @@ #include -#ifdef USE_SIMDJSON_JSON -# include "simdjson/simdjson.h" -#endif - -#ifdef USE_RAPIDJSON_JSON -# include "rapidjson/document.h" -#endif - -#ifdef USE_BOOST_JSON -# include -#endif - -#ifdef USE_NLOHMANN_JSON -# include "nlohmann/json.hpp" -#endif - -#ifdef USE_JSONCPP_JSON -# include -#endif +#include "simdjson/simdjson.h" #include "ram_t.h" @@ -35,26 +17,7 @@ private: ram_t m_ram; public: -#ifdef USE_SIMDJSON_JSON state_t(simdjson::dom::element serialised); -#endif - -#ifdef USE_RAPIDJSON_JSON - state_t(const rapidjson::Value& serialised); -#endif - -#ifdef USE_BOOST_JSON - state_t(const boost::json::object& serialised); - state_t(const boost::json::value& serialised); -#endif - -#ifdef USE_NLOHMANN_JSON - state_t(const nlohmann::json& serialised); -#endif - -#ifdef USE_JSONCPP_JSON - state_t(const Json::Value& serialised); -#endif [[nodiscard]] constexpr auto pc() const noexcept { return m_pc; } [[nodiscard]] constexpr auto s() const noexcept { return m_s; } diff --git a/M6502/HarteTest_6502/stdafx.h b/M6502/HarteTest_6502/stdafx.h index ee68a04..322ed16 100644 --- a/M6502/HarteTest_6502/stdafx.h +++ b/M6502/HarteTest_6502/stdafx.h @@ -21,43 +21,4 @@ #include #include -//#define TEST_JSON_PERFORMANCE - -#define USE_SIMDJSON_JSON // 13 seconds (19) -//#define USE_RAPIDJSON_JSON // 19 seconds (22) -//#define USE_BOOST_JSON // 26 seconds (32) -//#define USE_NLOHMANN_JSON // 56 seconds (65) -//#define USE_JSONCPP_JSON // 80 seconds (87) - -#ifdef USE_SIMDJSON_JSON -# define JSON_PREFER_PASS_BY_VALUE -# define JSON_PREFER_REUSE_OF_PARSER -# define JSON_PREFER_ITERATOR_TO_INDEX -# define JSON_ACCESS_DATA_VIA_OBJECT -# include "simdjson/simdjson.h" -#endif - -#ifdef USE_RAPIDJSON_JSON -# define RAPIDJSON_HAS_STDSTRING 1 -# define RAPIDJSON_SSE42 -# define JSON_INSITU_PARSE -# define JSON_ACCESS_DATA_VIA_OBJECT -# include "rapidjson/document.h" -#endif - -#ifdef USE_BOOST_JSON -# define JSON_ACCESS_DATA_VIA_OBJECT -# include -#endif - -#ifdef USE_NLOHMANN_JSON -# define JSON_USE_IMPLICIT_CONVERSIONS 0 -# define JSON_ACCESS_DATA_VIA_OBJECT -# include "nlohmann/json.hpp" -#endif - -#ifdef USE_JSONCPP_JSON -# define JSON_PREFER_REUSE_OF_PARSER -# define JSON_ACCESS_DATA_VIA_OBJECT -# include -#endif +#include "simdjson/simdjson.h" diff --git a/M6502/HarteTest_6502/test_t.cpp b/M6502/HarteTest_6502/test_t.cpp index 560527a..2c94feb 100644 --- a/M6502/HarteTest_6502/test_t.cpp +++ b/M6502/HarteTest_6502/test_t.cpp @@ -2,55 +2,8 @@ #include "test_t.h" #include -#ifdef USE_SIMDJSON_JSON - test_t::test_t(const simdjson::dom::element serialised) : m_name(serialised["name"]), m_initial_state(serialised["initial"]), m_final_state(serialised["final"]), m_cycles(serialised["cycles"].get_array()) {} - -#endif - -#ifdef USE_RAPIDJSON_JSON - -test_t::test_t(const rapidjson::Value& serialised) -: m_name(serialised["name"].GetString()), - m_initial_state(serialised["initial"]), - m_final_state(serialised["final"]), - m_cycles(serialised["cycles"]) {} - -#endif - -#ifdef USE_BOOST_JSON - -test_t::test_t(const boost::json::object& serialised) -: m_name(serialised.at("name").get_string()), - m_initial_state(serialised.at("initial")), - m_final_state(serialised.at("final")), - m_cycles(serialised.at("cycles")) {} - -test_t::test_t(const boost::json::value& serialised) -: test_t(serialised.get_object()) {} - -#endif - -#ifdef USE_NLOHMANN_JSON - -test_t::test_t(const nlohmann::json& serialised) -: m_name(serialised["name"].get()), - m_initial_state(serialised["initial"]), - m_final_state(serialised["final"]), - m_cycles(serialised["cycles"]) {} - -#endif - -#ifdef USE_JSONCPP_JSON - -test_t::test_t(const Json::Value& serialised) -: m_name(serialised["name"].asString()), - m_initial_state(serialised["initial"]), - m_final_state(serialised["final"]), - m_cycles(serialised["cycles"]) {} - -#endif diff --git a/M6502/HarteTest_6502/test_t.h b/M6502/HarteTest_6502/test_t.h index 815bf2e..6dd100f 100644 --- a/M6502/HarteTest_6502/test_t.h +++ b/M6502/HarteTest_6502/test_t.h @@ -2,25 +2,7 @@ #include -#ifdef USE_SIMDJSON_JSON -# include "simdjson/simdjson.h" -#endif - -#ifdef USE_RAPIDJSON_JSON -# include "rapidjson/document.h" -#endif - -#ifdef USE_BOOST_JSON -# include -#endif - -#ifdef USE_NLOHMANN_JSON -# include "nlohmann/json.hpp" -#endif - -#ifdef USE_JSONCPP_JSON -# include -#endif +#include "simdjson/simdjson.h" #include "cycles_t.h" #include "state_t.h" @@ -33,27 +15,7 @@ private: cycles_t m_cycles; public: - -#ifdef USE_SIMDJSON_JSON test_t(simdjson::dom::element serialised); -#endif - -#ifdef USE_RAPIDJSON_JSON - test_t(const rapidjson::Value& serialised); -#endif - -#ifdef USE_BOOST_JSON - test_t(const boost::json::object& serialised); - test_t(const boost::json::value& serialised); -#endif - -#ifdef USE_NLOHMANN_JSON - test_t(const nlohmann::json& serialised); -#endif - -#ifdef USE_JSONCPP_JSON - test_t(const Json::Value& serialised); -#endif [[nodiscard]] constexpr const auto& name() const noexcept { return m_name; } [[nodiscard]] constexpr const auto& initial_state() const noexcept { return m_initial_state; } diff --git a/M6502/HarteTest_6502/tests.cpp b/M6502/HarteTest_6502/tests.cpp index 085da1d..0bb23d9 100644 --- a/M6502/HarteTest_6502/tests.cpp +++ b/M6502/HarteTest_6502/tests.cpp @@ -24,23 +24,7 @@ int main() { opcode.load(); opcode.parse(); -#ifdef USE_SIMDJSON_JSON const auto opcode_test_array = opcode.raw().get_array(); -#endif -#ifdef USE_RAPIDJSON_JSON - const auto& opcode_test_array = opcode.raw().GetArray(); -#endif -#ifdef USE_BOOST_JSON - const auto& opcode_test_array = opcode.raw().get_array(); -#endif -#ifdef USE_NLOHMANN_JSON - const auto& opcode_test_array = opcode.raw(); - assert(opcode_test_array.is_array()); -#endif -#ifdef USE_JSONCPP_JSON - const auto& opcode_test_array = opcode.raw(); - assert(opcode_test_array.is_array()); -#endif bool opcode_bad = false; for (const auto& opcode_test_element : opcode_test_array) { @@ -48,7 +32,6 @@ int main() { const auto opcode_test = test_t(opcode_test_element); TestRunner runner(opcode_test); -#ifndef TEST_JSON_PERFORMANCE const auto good = runner.check(); if (!good) { if (!opcode_bad) { @@ -58,7 +41,6 @@ int main() { opcode_bad = true; } } -#endif } if (opcode_bad) ++bad_opcode_count; @@ -71,4 +53,4 @@ int main() { << "Elapsed time: " << seconds << " seconds" << ", bad opcode count: " << bad_opcode_count << std::endl; -} \ No newline at end of file +}