diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-08-05 18:48:59 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-08-11 01:43:14 +0100 |
commit | ebfc6845660c082a61f32b60903808910e39251c (patch) | |
tree | efaf84cc62d361bc304dd7dbe7d7321742f31bd4 | |
parent | Misc tidy up in db module (diff) | |
download | slicer-ebfc6845660c082a61f32b60903808910e39251c.tar.bz2 slicer-ebfc6845660c082a61f32b60903808910e39251c.tar.xz slicer-ebfc6845660c082a61f32b60903808910e39251c.zip |
WIP perf tests
-rw-r--r-- | slicer/test/Jamfile.jam | 29 | ||||
-rw-r--r-- | slicer/test/perf.cpp | 81 |
2 files changed, 110 insertions, 0 deletions
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 <library>../json//slicer-json ; +run + [ obj perf : perf.cpp : + <slicer>pure + <define>ROOT=\"$(me)\" + <use>types + <implicit-dependency>types + <use>benchmark + <use>stdc++fs + <use>..//adhocutil + <use>common + <use>../slicer//slicer + <implicit-dependency>../slicer//slicer + <use>../xml//slicer-xml + <use>../json//slicer-json + ] + : : : + <library>benchmark + <library>stdc++fs + <library>common + <library>types + <library>../slicer//slicer + <implicit-dependency>../slicer//slicer + <library>../xml//slicer-xml + <library>../json//slicer-json + <library>..//adhocutil + <variant>profile:<testing.execute>on + <testing.execute>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 <benchmark/benchmark.h> +#include <definedDirs.h> +#include <enums.h> +#include <json.h> +#include <json/serializer.h> +#include <locals.h> +#include <optionals.h> +#include <slicer/slicer.h> +#include <xml.h> +#include <xml/serializer.h> +// Must go last +#include <libxml++/parsers/domparser.h> + +class CoreFixture : public benchmark::Fixture { +protected: + template<typename Deserializer, typename T, typename... Args> + void + runDeserialize(benchmark::State & state, Args &&... args) + { + for (auto _ : state) { + benchmark::DoNotOptimize(Slicer::DeserializeAny<Deserializer, T>(std::forward<Args>(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<ds, type>(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(); |