-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.cpp
More file actions
84 lines (65 loc) · 2.14 KB
/
run.cpp
File metadata and controls
84 lines (65 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "executor/executor.h"
#include <latch>
#include <ranges>
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/benchmark/catch_benchmark.hpp>
using namespace std::chrono_literals;
namespace {
struct EmptyTask : Task {
void Run() override {
}
};
class LatchSignaler : public Task {
public:
LatchSignaler(std::latch* latch) : latch_{latch} {
}
void Run() override {
latch_->count_down();
}
private:
std::latch* latch_;
};
} // namespace
TEST_CASE("Simple") {
const auto num_threads = GENERATE(1, 2, 4);
auto pool = MakeThreadPoolExecutor(num_threads);
BENCHMARK("Simple:" + std::to_string(num_threads)) {
auto task = std::make_shared<EmptyTask>();
pool->Submit(task);
task->Wait();
};
}
TEST_CASE("FanoutFanin") {
const auto num_threads = GENERATE(1, 2, 10);
const auto size = GENERATE(1, 10, 100);
auto pool = MakeThreadPoolExecutor(num_threads);
BENCHMARK("FanoutFanin:" + std::to_string(num_threads) + ':' + std::to_string(size)) {
auto first_task = std::make_shared<EmptyTask>();
auto last_task = std::make_shared<EmptyTask>();
for (auto i = 0; i < size; ++i) {
auto middle_task = std::make_shared<EmptyTask>();
middle_task->AddDependency(first_task);
last_task->AddDependency(middle_task);
pool->Submit(middle_task);
}
pool->Submit(first_task);
pool->Submit(last_task);
last_task->Wait();
};
}
TEST_CASE("ScalableTimers") {
static constexpr auto kCount = 100'000ul;
const auto num_threads = GENERATE(1, 2, 5);
auto pool = MakeThreadPoolExecutor(num_threads);
BENCHMARK("ScalableTimers:" + std::to_string(num_threads)) {
std::latch latch{kCount};
auto at = std::chrono::system_clock::now() + 5ms;
for (auto i : std::views::iota(0ul, kCount)) {
auto task = std::make_shared<LatchSignaler>(&latch);
task->SetTimeTrigger(at + std::chrono::microseconds{(i * i) % 1'000});
pool->Submit(task);
}
latch.wait();
};
}