From ebfc6845660c082a61f32b60903808910e39251c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 5 Aug 2023 18:48:59 +0100 Subject: WIP perf tests --- slicer/test/Jamfile.jam | 29 ++++++++++++++++++ slicer/test/perf.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 slicer/test/perf.cpp diff --git a/slicer/test/Jamfile.jam b/slicer/test/Jamfile.jam index 8fd70a5..6fcffa0 100644 --- a/slicer/test/Jamfile.jam +++ b/slicer/test/Jamfile.jam @@ -3,6 +3,7 @@ import ./slicer.jam ; lib dl ; lib stdc++fs ; lib boost_date_time ; +lib benchmark ; lib icetypes : [ glob *.ice ] @@ -111,3 +112,31 @@ run streams.cpp ../json//slicer-json ; +run + [ obj perf : perf.cpp : + pure + ROOT=\"$(me)\" + types + types + benchmark + stdc++fs + ..//adhocutil + common + ../slicer//slicer + ../slicer//slicer + ../xml//slicer-xml + ../json//slicer-json + ] + : : : + benchmark + stdc++fs + common + types + ../slicer//slicer + ../slicer//slicer + ../xml//slicer-xml + ../json//slicer-json + ..//adhocutil + profile:on + off + : perf ; diff --git a/slicer/test/perf.cpp b/slicer/test/perf.cpp new file mode 100644 index 0000000..0ea775b --- /dev/null +++ b/slicer/test/perf.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// Must go last +#include + +class CoreFixture : public benchmark::Fixture { +protected: + template + void + runDeserialize(benchmark::State & state, Args &&... args) + { + for (auto _ : state) { + benchmark::DoNotOptimize(Slicer::DeserializeAny(std::forward(args)...)); + } + } +}; + +struct JsonValueFromFile : public json::Value { + explicit JsonValueFromFile(const std::filesystem::path & path) : + json::Value {[&path] { + std::ifstream in {path}; + return json::parseValue(in); + }()} + { + } +}; + +#define DESERIALIZE_TEST(name, type, ds, ext, obj, suf) \ + BENCHMARK_F(CoreFixture, name##_##ext)(benchmark::State & state) \ + { \ + obj dom {rootDir / "initial/" #name "." #ext}; \ + runDeserialize(state, dom suf); \ + } + +#define XML_DESERIALIZE_TEST(name, type) \ + DESERIALIZE_TEST(name, type, Slicer::XmlDocumentDeserializer, xml, xmlpp::DomParser, .get_document()) +XML_DESERIALIZE_TEST(attributemap, TestXml::Maps); +XML_DESERIALIZE_TEST(bare, TestXml::BareContainers); +XML_DESERIALIZE_TEST(someenums, TestModule::SomeEnumsPtr); +XML_DESERIALIZE_TEST(enum, TestModule::SomeNumbers); +XML_DESERIALIZE_TEST(elementmap, TestXml::Maps); +XML_DESERIALIZE_TEST(builtins, TestModule::BuiltInsPtr); +XML_DESERIALIZE_TEST(entityref, TestXml::EntityRef); +XML_DESERIALIZE_TEST(int, int); +XML_DESERIALIZE_TEST(isodate, TestModule::IsoDate); +XML_DESERIALIZE_TEST(seqOfClass, TestModule::Classes); +XML_DESERIALIZE_TEST(simpleArray2, TestModule::SimpleSeq); +XML_DESERIALIZE_TEST(string, std::string); +XML_DESERIALIZE_TEST(struct, TestModule::StructType); +XML_DESERIALIZE_TEST(xmlattr, TestModule::ClassClassPtr); +#undef XML_DESERIALIZE_TEST + +#define JSON_DESERIALIZE_TEST(name, type) \ + DESERIALIZE_TEST(name, type, Slicer::JsonValueDeserializer, json, JsonValueFromFile, ) +JSON_DESERIALIZE_TEST(builtins2, TestModule::BuiltInsPtr); +JSON_DESERIALIZE_TEST(builtins3, TestModule::BuiltInsPtr); +JSON_DESERIALIZE_TEST(localClass, Locals::LocalClassPtr); +JSON_DESERIALIZE_TEST(localSubClass, Locals::LocalSubClassPtr); +JSON_DESERIALIZE_TEST(localSub2Class, Locals::LocalSub2ClassPtr); +JSON_DESERIALIZE_TEST(objectmap, TestJson::Properties); +JSON_DESERIALIZE_TEST(objectmapMember, TestJson::HasProperitiesPtr); +JSON_DESERIALIZE_TEST(optionals2, TestModule::Optionals2Ptr); +JSON_DESERIALIZE_TEST(optionals3, TestModule::Optionals2Ptr); +JSON_DESERIALIZE_TEST(optionals5, TestModule::Optionals2Ptr); +JSON_DESERIALIZE_TEST(seqOfClass2, TestModule::Classes); +JSON_DESERIALIZE_TEST(simpleArray1, TestModule::SimpleSeq); +JSON_DESERIALIZE_TEST(string2, std::string); +JSON_DESERIALIZE_TEST(struct2, TestModule::StructType); +#undef JSON_DESERIALIZE_TEST + +#undef DESERIALIZE_TEST + +BENCHMARK_MAIN(); -- cgit v1.2.3