Skip to content

Commit

Permalink
add scheduler bench
Browse files Browse the repository at this point in the history
Signed-off-by: wineway <wangyuweihx@gmail.com>
  • Loading branch information
wineway committed Aug 19, 2024
1 parent 2d62941 commit 2e744f3
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ if (INSTALL_SQKIO)
RUNTIME DESTINATION ${SQKIO_INSTALL_BINDIR})
endif()
add_subdirectory(common)
add_subdirectory(core)
if (WITH_NET_FABRIC)
add_subdirectory(fabric)
endif()
Expand Down
15 changes: 15 additions & 0 deletions src/tests/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
project(core-test)

add_executable(core-bench
core_bench.cc
)

foreach(X IN ITEMS core-bench)
target_include_directories(${X} PRIVATE ${SPDLOG_SOURCE_DIR}/include)
target_link_libraries(${X} PRIVATE core nanobench)
if (INSTALL_SQKIO)
install(TARGETS ${X}
RUNTIME DESTINATION ${SQKIO_INSTALL_BINDIR})
endif()
endforeach()

81 changes: 81 additions & 0 deletions src/tests/core/core_bench.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include <nanobench.h>

#include <core.hpp>

using namespace ankerl::nanobench;

struct SqkBench: public Bench {
SqkBench& name(std::string name) {
Bench::name(name);
return *this;
}

SqkBench& minEpochIterations(uint64_t cnt) {
Bench::minEpochIterations(cnt);
return *this;
}

template<typename Op>
sqk::Task<void> run(Op&& op) {
detail::IterationLogic iterationLogic(*this);
auto& pc = detail::performanceCounters();

while (auto n = iterationLogic.numIters()) {
pc.beginMeasure();
Clock::time_point const before = Clock::now();
while (n-- > 0) {
co_await op();
}
Clock::time_point const after = Clock::now();
pc.endMeasure();
pc.updateResults(iterationLogic.numIters());
iterationLogic.add(after - before, pc);
}

sqk::scheduler->stop();
}
};

int i;

#define epochIterations (1000UL * 1000)

sqk::Task<int> run_bench() {
co_await SqkBench()
.name("sqk::scheduler benchmark")
.minEpochIterations(epochIterations)
.run([]() -> sqk::Task<void> {
i++;
doNotOptimizeAway(i);
co_return;
});
co_return 0;
}

int main(int argc, char* argv[]) {
sqk::scheduler = new sqk::SQKScheduler;
sqk::scheduler->enqueue(run_bench());
sqk::scheduler->run();

Bench()
.name("function benchmark")
.minEpochIterations(epochIterations)
.run([]() {
i++;
doNotOptimizeAway(i);
return;
});

Bench()
.name("thread benchmark")
.minEpochIterations(epochIterations / 1000)
.run([]() {
std::jthread thread([]() {
i++;
doNotOptimizeAway(i);
return;
});
thread.join();
});
return 0;
}

0 comments on commit 2e744f3

Please sign in to comment.