Skip to content

Commit bbb76e7

Browse files
committed
started working on benchmarks
added basic conan file
1 parent a421eb3 commit bbb76e7

4 files changed

Lines changed: 3592 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ project(chron-cpp VERSION ${ORYX_CHRON_VERSION} LANGUAGES CXX)
99
message(STATUS "Build ${PROJECT_NAME}: ${PROJECT_VERSION}")
1010

1111
option(ORYX_CHRON_BUILD_SHARED_LIBS "Build shared library" ${BUILD_SHARED_LIBS})
12+
option(ORYX_CHRON_BUILD_BENCHMARKS "Build Benchmarks" OFF)
1213
option(ORYX_CHRON_BUILD_TESTS "Build tests" OFF)
1314
option(ORYX_CHRON_INSTALL "Install the project" OFF)
1415
option(ORYX_CHRON_SANITIZE_ADDRESS "Enable address sanitizer in tests" OFF)
@@ -106,6 +107,22 @@ if(ORYX_CHRON_BUILD_TESTS)
106107
endif()
107108
endif()
108109

110+
if(ORYX_CHRON_BUILD_BENCHMARKS)
111+
set(bench_exe ${PROJECT_NAME}_benchmarks)
112+
include(FetchContent)
113+
FetchContent_Declare(
114+
libcron
115+
GIT_REPOSITORY https://github.com/PerMalmberg/libcron.git
116+
GIT_TAG master
117+
OVERRIDE_FIND_PACKAGE
118+
)
119+
FetchContent_MakeAvailable(libcron)
120+
121+
122+
add_executable(${bench_exe} benchmarks/main.cpp)
123+
target_link_libraries(${bench_exe} PRIVATE ${PROJECT_NAME} libcron)
124+
endif()
125+
109126
if (ORYX_CHRON_INSTALL)
110127
include(GNUInstallDirs)
111128
include(CMakePackageConfigHelpers)

benchmarks/main.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#define ANKERL_NANOBENCH_IMPLEMENT
2+
#include "nanobench.hpp"
3+
4+
#include <oryx/chron/parser.hpp>
5+
#include <oryx/chron/randomization.hpp>
6+
7+
#include <libcron/CronData.h>
8+
#include <libcron/CronRandomization.h>
9+
10+
using namespace oryx::chron;
11+
using namespace ankerl;
12+
13+
const std::string kRandomSchedule = "R(0-59) R(0-59) R(0-23) R(1-31) R(JAN-DEC) ?";
14+
15+
template <typename Parser>
16+
void bench(ankerl::nanobench::Bench* bench, char const* name) {
17+
Parser parser;
18+
Randomization rng;
19+
20+
bench->run(name, [&] { ankerl::nanobench::doNotOptimizeAway(parser(rng.Parse(kRandomSchedule).value()).value()); });
21+
}
22+
23+
void bench(ankerl::nanobench::Bench* bench, char const* name) {
24+
Randomization rng;
25+
26+
bench->run(name, [&] {
27+
ankerl::nanobench::doNotOptimizeAway(libcron::CronData::create(rng.Parse(kRandomSchedule).value()));
28+
});
29+
}
30+
31+
auto main() -> int {
32+
static const auto kCachedParse = CachedExpressionParser();
33+
static const auto kMtx = CachedExpressionParser<std::mutex>();
34+
35+
ankerl::nanobench::Bench b;
36+
b.title("Parsing randomized Expressions").epochIterations(20000).relative(true).performanceCounters(true);
37+
38+
bench<ExpressionParser>(&b, "ExpressionParser");
39+
bench<CachedExpressionParser<>>(&b, "CachedExpressionParser<NullMutex>");
40+
bench<CachedExpressionParser<std::mutex>>(&b, "CachedExpressionParser<std::mutex>");
41+
bench(&b, "libcron::CronData::create");
42+
43+
ankerl::nanobench::Bench b2;
44+
Randomization rng1;
45+
libcron::CronRandomization rng2;
46+
47+
b2.title("Randomization").epochIterations(100000).relative(true).performanceCounters(true);
48+
b2.run("chron-cpp", [&] {
49+
auto r = rng1.Parse(kRandomSchedule);
50+
nanobench::doNotOptimizeAway(r);
51+
});
52+
b2.run("libcron", [&] {
53+
auto r = rng2.parse(kRandomSchedule);
54+
nanobench::doNotOptimizeAway(r);
55+
});
56+
}

0 commit comments

Comments
 (0)