From a867631393002e4a3c499e76da3db3b078229106 Mon Sep 17 00:00:00 2001 From: David Allemang Date: Fri, 16 Sep 2022 10:15:00 -0400 Subject: [PATCH] add benchmark executable --- tc/CMakeLists.txt | 1 + tc/bench/CMakeLists.txt | 2 ++ tc/bench/benchmark.cpp | 75 ++++++++++++++++++++++++++++++++++++++++ tc/include/tc/cosets.hpp | 2 +- 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 tc/bench/CMakeLists.txt create mode 100644 tc/bench/benchmark.cpp diff --git a/tc/CMakeLists.txt b/tc/CMakeLists.txt index ef41cad..fa3e134 100644 --- a/tc/CMakeLists.txt +++ b/tc/CMakeLists.txt @@ -11,3 +11,4 @@ add_library(tc target_include_directories(tc PUBLIC include) add_subdirectory(test) +add_subdirectory(bench) diff --git a/tc/bench/CMakeLists.txt b/tc/bench/CMakeLists.txt new file mode 100644 index 0000000..c12a5b7 --- /dev/null +++ b/tc/bench/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(benchmark benchmark.cpp) +target_link_libraries(benchmark PUBLIC tc fmt::fmt) diff --git a/tc/bench/benchmark.cpp b/tc/bench/benchmark.cpp new file mode 100644 index 0000000..e6a8878 --- /dev/null +++ b/tc/bench/benchmark.cpp @@ -0,0 +1,75 @@ +#include +#include +#include + +#include +#include + +#include +#include + +#define NAMED(x) #x, x + +void bench(std::string group_expr, tc::Group group, const std::vector &gens) { + std::clock_t s = std::clock(); + tc::Cosets cosets = tc::solve(group, gens); + std::clock_t e = std::clock(); + + double time = (double) (e - s) / CLOCKS_PER_SEC; + tc::Coset order = cosets.size(); + size_t cos_s = (size_t) (order / time); + + std::string name = fmt::format("{}/{}", group_expr, gens); + std::string row = fmt::format( + "{:>24},{:>10},{:>8.3f}s,{:>10L}", + name, order, time, cos_s + ); + fmt::print("{}\n", row); +} + +template +tc::Group sch(T ...arg) { + std::vector mults{arg...,}; + return tc::schlafli(mults); +} + +int main(int argc, char *argv[]) { + std::vector args(argv + 1, argv + argc); + + using namespace tc::group; + + fmt::print("{:>24},{:>10},{:>9},{:>10}\n", "NAME", "ORDER", "TIME", "COS/S"); + + bench(NAMED(H(2)), {}); + bench(NAMED(H(3)), {}); + bench(NAMED(H(4)), {}); + bench(NAMED(sch(5, 3, 3, 2)), {}); + bench(NAMED(sch(5, 3, 3, 2)), {0}); + bench(NAMED(sch(5, 3, 3, 2)), {1}); + bench(NAMED(sch(5, 3, 3, 2)), {2}); + bench(NAMED(sch(5, 3, 3, 2)), {3}); + bench(NAMED(sch(5, 3, 3, 2)), {4}); + bench(NAMED(sch(5, 3, 3, 2)), {0, 1}); + bench(NAMED(sch(5, 3, 3, 2)), {0, 2}); + bench(NAMED(sch(5, 3, 3, 2)), {1, 2}); + bench(NAMED(sch(5, 3, 3, 2)), {0, 3}); + bench(NAMED(sch(5, 3, 3, 2)), {1, 3}); + bench(NAMED(sch(5, 3, 3, 2)), {2, 3}); + bench(NAMED(sch(5, 3, 3, 2)), {0, 4}); + bench(NAMED(sch(5, 3, 3, 2)), {1, 4}); + bench(NAMED(sch(5, 3, 3, 2)), {2, 4}); + bench(NAMED(sch(5, 3, 3, 2)), {3, 4}); + + bench(NAMED(T(100)), {}); + bench(NAMED(T(500)), {}); + bench(NAMED(T(1000)), {}); + + bench(NAMED(E(6)), {}); + bench(NAMED(E(7)), {}); + + bench(NAMED(B(6)), {}); + bench(NAMED(B(7)), {}); + bench(NAMED(B(8)), {}); + + return EXIT_SUCCESS; +} diff --git a/tc/include/tc/cosets.hpp b/tc/include/tc/cosets.hpp index 4d59b4b..4e9bfde 100644 --- a/tc/include/tc/cosets.hpp +++ b/tc/include/tc/cosets.hpp @@ -67,7 +67,7 @@ namespace tc { } - [[nodiscard]] size_t size() const { + [[nodiscard]] tc::Coset size() const { return path.size(); } };