37 using util::isLimited;
38 using std::this_thread::sleep_for;
39 using std::chrono_literals::operator
""ms;
40 using std::chrono_literals::operator
""us;
41 using std::chrono::microseconds;
49 isNumEq (
double d1,
double d2)
51 return 0.001 > abs(d1-d2);
93 double time = watch.calcCumulatedTime();
104 watch.expectThreads(1)
105 .expectIncidents(20);
126 CHECK (isLimited (15500, stat.cumulatedTime, 17800));
127 CHECK (isLimited ( 8500, stat.coveredTime, 10000));
128 CHECK (10== stat.eventCnt);
129 CHECK (5 == stat.activationCnt);
130 CHECK (0 == stat.cntCase(0));
131 CHECK (2 == stat.cntCase(1));
132 CHECK (1 == stat.cntCase(2));
133 CHECK (2 == stat.cntCase(3));
134 CHECK (0 == stat.cntCase(4));
135 CHECK (0 == stat.timeCase(0));
136 CHECK (isLimited ( 5500, stat.timeCase(1), 6800));
137 CHECK (isLimited ( 3500, stat.timeCase(2), 4500));
138 CHECK (isLimited ( 5500, stat.timeCase(3), 6800));
139 CHECK (0 == stat.timeCase(4));
140 CHECK (5 == stat.cntThread(0));
141 CHECK (0 == stat.cntThread(1));
142 CHECK (stat.activeTime == stat.timeThread(0));
143 CHECK (0 == stat.timeThread(1));
144 CHECK (isNumEq (stat.activeTime, stat.coveredTime));
145 CHECK (isNumEq (stat.cumulatedTime , stat.timeCase(1) + stat.timeCase(2) + stat.timeCase(3)));
155 watch.expectThreads(2)
167 auto run_parallel = [&]
175 double runTime = test::benchmarkTime (run_parallel);
181 CHECK (runTime > stat.coveredTime);
182 CHECK (stat.coveredTime < stat.cumulatedTime);
183 CHECK (stat.activeTime <= stat.cumulatedTime);
184 CHECK (8 == stat.eventCnt);
185 CHECK (4 == stat.activationCnt);
186 CHECK (2 == stat.cntCase(0));
187 CHECK (0 == stat.cntCase(1));
188 CHECK (2 == stat.cntCase(2));
189 CHECK (0 == stat.cntCase(3));
190 CHECK (2 == stat.cntThread(0));
191 CHECK (2 == stat.cntThread(1));
192 CHECK (0 == stat.cntThread(3));
193 CHECK (isLimited(1, stat.avgConcurrency, 2));
194 CHECK (0 == stat.timeAtConc(0));
195 CHECK (0 < stat.timeAtConc(1));
196 CHECK (0 < stat.timeAtConc(2));
197 CHECK (0 == stat.timeAtConc(3));
198 CHECK (stat.timeAtConc(1) < stat.coveredTime);
199 CHECK (stat.timeAtConc(2) < stat.coveredTime);
201 CHECK (isNumEq (stat.avgConcurrency, (1*stat.timeAtConc(1) + 2*stat.timeAtConc(2))
202 / stat.coveredTime));
204 CHECK (isNumEq (stat.cumulatedTime , stat.timeCase(0) + stat.timeCase(2)));
205 CHECK (isNumEq (stat.activeTime , stat.timeThread(0) + stat.timeThread(1)));
206 CHECK (isNumEq (stat.coveredTime , stat.timeAtConc(1) + stat.timeAtConc(2)));
208 CHECK (stat.timeCase(2) < stat.timeCase(0));
209 CHECK (isNumEq (stat.coveredTime , stat.timeCase(0) - stat.timeAtConc(2)));
218 constexpr
size_t CONCURR = 16;
219 const size_t REPETITIONS = 100;
222 watch.expectThreads(CONCURR)
223 .expectIncidents(10000);
226 uint delay = 100 + rand() % 800;
228 sleep_for (microseconds(delay));
230 sleep_for (microseconds(delay));
236 auto [runTime, sum] = test::threadBenchmark<CONCURR> (act, REPETITIONS);
238 CHECK (sum == CONCURR*REPETITIONS);
239 CHECK (isLimited (900, runTime, 1400));
245 CHECK (isLimited (900*REPETITIONS, stat.coveredTime, 1400*REPETITIONS));
246 CHECK (stat.activeTime > 900 * REPETITIONS*CONCURR);
247 CHECK (stat.activationCnt == 2*REPETITIONS*CONCURR);
248 CHECK (stat.cntCase(0) == REPETITIONS*CONCURR);
249 CHECK (stat.cntCase(1) == 0);
250 CHECK (stat.cntCase(2) == REPETITIONS*CONCURR);
252 CHECK (isLimited(CONCURR/2, stat.avgConcurrency, CONCURR));
255 for (uint i=0; i<CONCURR; ++i)
256 CHECK (isLimited(REPETITIONS*900, stat.timeThread(i), REPETITIONS*1400));
258 CHECK (0 == stat.timeThread(CONCURR));
259 CHECK (0 == stat.timeAtConc(CONCURR+1));
261 CHECK (isLimited(REPETITIONS*900, stat.timeAtConc(CONCURR), REPETITIONS*1200));
Variant of the standard case, requiring to wait and join() on the termination of this thread...
void verify_incidentCount()
Functions to perform (multithreaded) timing measurement on a given functor.
Record and evaluate concurrent activations.
Implementation namespace for support and library code.
void verify_concurrencyStatistic()
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
lib::Result< RES > join()
put the caller into a blocking wait until this thread has terminated
Convenience front-end to simplify and codify basic thread handling.
A recorder for concurrent incidences.
void perform_multithreadStressTest()
Statistic evaluate()
Visit all data captured thus far, construct an unified timeline and then compute statistics evaluatio...