Skip to content

Commit ce6a59a

Browse files
Merge pull request #6 from BestITUserEUW/feature/conan-file-benchmarks
Feature/conan file benchmarks
2 parents a421eb3 + c807387 commit ce6a59a

5 files changed

Lines changed: 3623 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)

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,25 @@ when using randomization, i.e. mutual exclusiveness and no extra spaces.
285285
| 0 R(45-15) */12 ? * * | A random minute between 45-15, inclusive, every 12 hours.
286286
|0 0 0 ? R(DEC-MAR) R(SAT-SUN)| On the hour, on a random month december to march, on a random weekday saturday to sunday.
287287

288+
## Performance
289+
290+
These are some initial benchmarks on cron-parsing and cron randomization comparing against libcron:
291+
292+
OS: Linux
293+
CPU: AMD Ryzen 9 7950X 16-Core Processor
294+
295+
| relative | ns/op | op/s | err% | ins/op | cyc/op | IPC | bra/op | miss% | total | Parsing randomized Expressions
296+
|---------:|--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:-------------------------------
297+
| 100.0% | 102,326.11 | 9,772.68 | 1.2% | 1,013,843.99 | 548,690.22 | 1.848 | 152,240.32 | 0.3% | 23.50 | `ExpressionParser`
298+
| 9.2% | 1,116,211.84 | 895.89 | 40.5% | 16,046,595.84 | 5,985,076.41 | 2.681 | 2,785,616.84 | 0.0% | 247.82 | `CachedExpressionParser<NullMutex>`
299+
| 9.3% | 1,103,677.48 | 906.06 | 40.3% | 16,042,923.93 | 5,952,656.76 | 2.695 | 2,785,005.43 | 0.1% | 245.24 | `CachedExpressionParser<std::mutex>`
300+
| 7.9% | 1,298,631.94 | 770.04 | 0.2% | 13,982,049.29 | 7,033,908.92 | 1.988 | 2,239,027.96 | 0.4% | 285.72 | `libcron::CronData::create`
301+
302+
| relative | ns/op | op/s | err% | ins/op | cyc/op | IPC | bra/op | miss% | total | Randomization
303+
|---------:|--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:--------------
304+
| 100.0% | 85,454.44 | 11,702.14 | 0.5% | 879,301.99 | 463,006.51 | 1.899 | 134,616.91 | 0.3% | 93.98 | `chron-cpp`
305+
| 5.7% | 1,493,531.23 | 669.55 | 0.2% | 16,608,204.87 | 8,084,464.40 | 2.054 | 2,685,597.92 | 0.4% | 1,643.85 | `libcron`
306+
288307
## Adding this library to your project
289308

290309
```cmake

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)