fairness  v1.0.0
A collection of advanced syncronization mechanisms.
Loading...
Searching...
No Matches
standard_shared_mutex_benchmark.hpp
Go to the documentation of this file.
1
14#include <shared_mutex>
15#include "../utils/thread_utils.hpp"
16
18 std::shared_mutex m;
19
20 void lock_unlock_benchmark(benchmark::State& state) {
21 for (auto _ : state){
22 m.lock();
23 m.unlock();
24 }
25 }
26
27 void shared_lock_unlock_benchmark(benchmark::State& state) {
28 for (auto _ : state){
29 m.lock_shared();
30 m.unlock_shared();
31 }
32 }
33
34 void pipeline_benchmark_long(benchmark::State& state) {
35 std::array<int, 8> preCT {20, 15, 20, 30, 10, 5, 5, 20};
36 int CT = 10;
37 std::array<int, 8> postCT {50, 30, 20, 25, 10, 15, 15, 45};
38
39 for (auto _ : state) {
40 utils::thread::thread_function<utils::thread::LockLevel::Unique, utils::waiting::WaitingLevel::Milli>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()]);
41 }
42 }
43
44 void shared_pipeline_benchmark_long(benchmark::State& state) {
45 std::array<int, 8> preCT {20, 15, 20, 30, 10, 5, 5, 20};
46 int CT = 10;
47 std::array<int, 8> postCT {50, 30, 20, 25, 10, 15, 15, 45};
48
49 for (auto _ : state) {
50 utils::thread::thread_function<utils::thread::LockLevel::Shared, utils::waiting::WaitingLevel::Milli>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()]);
51 }
52 }
53
54 void pipeline_benchmark_gaming(benchmark::State& state) {
55 std::array<int, 8> preCT {2000, 1500, 2000, 3000, 1000, 500, 500, 2000};
56 int CT = 1000;
57 std::array<int, 8> postCT {5000, 3000, 2000, 2500, 1000, 1500, 1500, 4500};
58
59 for (auto _ : state) {
60 utils::thread::thread_function<utils::thread::LockLevel::Unique, utils::waiting::WaitingLevel::Micro>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()]);
61 }
62 }
63
64 void shared_pipeline_benchmark_gaming(benchmark::State& state) {
65 std::array<int, 8> preCT {2000, 1500, 2000, 3000, 1000, 500, 500, 2000};
66 int CT = 1000;
67 std::array<int, 8> postCT {5000, 3000, 2000, 2500, 1000, 1500, 1500, 4500};
68
69 for (auto _ : state) {
70 utils::thread::thread_function<utils::thread::LockLevel::Shared, utils::waiting::WaitingLevel::Micro>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()]);
71 }
72 }
73
74 void pipeline_benchmark_audio(benchmark::State& state) {
75 std::array<int, 8> prios {0, 1, 2, 1, 3, 2, 2, 0};
76 std::array<int, 8> preCT {200, 150, 200, 300, 100, 50, 50, 200};
77 int CT = 100;
78 std::array<int, 8> postCT {500, 300, 200, 250, 100, 150, 150, 450};
79
80 for (auto _ : state) {
81 utils::thread::thread_function<utils::thread::LockLevel::Unique, utils::waiting::WaitingLevel::Micro>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()]);
82 }
83 }
84
85 void shared_pipeline_benchmark_audio(benchmark::State& state) {
86 std::array<int, 8> prios {0, 1, 2, 1, 3, 2, 2, 0};
87 std::array<int, 8> preCT {200, 150, 200, 300, 100, 50, 50, 200};
88 int CT = 100;
89 std::array<int, 8> postCT {500, 300, 200, 250, 100, 150, 150, 450};
90
91 for (auto _ : state) {
92 utils::thread::thread_function<utils::thread::LockLevel::Shared, utils::waiting::WaitingLevel::Micro>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()]);
93 }
94 }
95
96 void pipeline_benchmark_fast(benchmark::State& state) { /* */
97 std::array<int, 8> prios {0, 1, 2, 1, 3, 2, 2, 0};
98 std::array<int, 8> preCT {2000, 1500, 2000, 3000, 1000, 500, 500, 2000};
99 int CT = 1000;
100 std::array<int, 8> postCT {5000, 3000, 2000, 2500, 1000, 1500, 1500, 4500};
101
102 for (auto _ : state) {
103 utils::thread::thread_function<utils::thread::LockLevel::Unique, utils::waiting::WaitingLevel::Nano>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()]);
104 }
105 }
106
107 void shared_pipeline_benchmark_fast(benchmark::State& state) { /* */
108 std::array<int, 8> prios {0, 1, 2, 1, 3, 2, 2, 0};
109 std::array<int, 8> preCT {2000, 1500, 2000, 3000, 1000, 500, 500, 2000};
110 int CT = 1000;
111 std::array<int, 8> postCT {5000, 3000, 2000, 2500, 1000, 1500, 1500, 4500};
112
113 for (auto _ : state) {
114 utils::thread::thread_function<utils::thread::LockLevel::Shared, utils::waiting::WaitingLevel::Nano>(m, preCT[state.thread_index()], CT, postCT[state.thread_index()]);
115 }
116 }
117}
Definition standard_shared_mutex_benchmark.hpp:17
void shared_pipeline_benchmark_long(benchmark::State &state)
Definition standard_shared_mutex_benchmark.hpp:44
void shared_pipeline_benchmark_fast(benchmark::State &state)
Definition standard_shared_mutex_benchmark.hpp:107
void shared_lock_unlock_benchmark(benchmark::State &state)
Definition standard_shared_mutex_benchmark.hpp:27
std::shared_mutex m
Definition standard_shared_mutex_benchmark.hpp:18
void pipeline_benchmark_audio(benchmark::State &state)
Definition standard_shared_mutex_benchmark.hpp:74
void shared_pipeline_benchmark_audio(benchmark::State &state)
Definition standard_shared_mutex_benchmark.hpp:85
void shared_pipeline_benchmark_gaming(benchmark::State &state)
Definition standard_shared_mutex_benchmark.hpp:64
void pipeline_benchmark_fast(benchmark::State &state)
Definition standard_shared_mutex_benchmark.hpp:96
void lock_unlock_benchmark(benchmark::State &state)
Definition standard_shared_mutex_benchmark.hpp:20
void pipeline_benchmark_long(benchmark::State &state)
Definition standard_shared_mutex_benchmark.hpp:34
void pipeline_benchmark_gaming(benchmark::State &state)
Definition standard_shared_mutex_benchmark.hpp:54
void thread_function(Lockable &lockable, int preCriticalTime, int criticalTime, int postCriticalTime, int p=0)
Definition thread_utils.hpp:26