28 using util::isLimited;
29 using std::this_thread::sleep_for;
30 using std::chrono_literals::operator
""ms;
31 using std::chrono_literals::operator
""us;
32 using std::chrono::microseconds;
40 isNumEq (
double d1,
double d2)
42 return 0.001 > abs(d1-d2);
84 double time = watch.calcCumulatedTime();
95 watch.expectThreads(1)
117 CHECK (isLimited (15500, stat.cumulatedTime, 17800));
118 CHECK (isLimited ( 8500, stat.coveredTime, 10000));
119 CHECK (10== stat.eventCnt);
120 CHECK (5 == stat.activationCnt);
121 CHECK (0 == stat.cntCase(0));
122 CHECK (2 == stat.cntCase(1));
123 CHECK (1 == stat.cntCase(2));
124 CHECK (2 == stat.cntCase(3));
125 CHECK (0 == stat.cntCase(4));
126 CHECK (0 == stat.timeCase(0));
127 CHECK (isLimited ( 5500, stat.timeCase(1), 6800));
128 CHECK (isLimited ( 3500, stat.timeCase(2), 4500));
129 CHECK (isLimited ( 5500, stat.timeCase(3), 6800));
130 CHECK (0 == stat.timeCase(4));
131 CHECK (5 == stat.cntThread(0));
132 CHECK (0 == stat.cntThread(1));
133 CHECK (stat.activeTime == stat.timeThread(0));
134 CHECK (0 == stat.timeThread(1));
135 CHECK (isNumEq (stat.activeTime, stat.coveredTime));
136 CHECK (isNumEq (stat.cumulatedTime , stat.timeCase(1) + stat.timeCase(2) + stat.timeCase(3)));
146 watch.expectThreads(2)
158 auto run_parallel = [&]
166 double runTime = test::benchmarkTime (run_parallel);
172 CHECK (runTime > stat.coveredTime);
173 CHECK (stat.coveredTime < stat.cumulatedTime);
174 CHECK (stat.activeTime <= stat.cumulatedTime);
175 CHECK (8 == stat.eventCnt);
176 CHECK (4 == stat.activationCnt);
177 CHECK (2 == stat.cntCase(0));
178 CHECK (0 == stat.cntCase(1));
179 CHECK (2 == stat.cntCase(2));
180 CHECK (0 == stat.cntCase(3));
181 CHECK (2 == stat.cntThread(0));
182 CHECK (2 == stat.cntThread(1));
183 CHECK (0 == stat.cntThread(3));
184 CHECK (isLimited(1, stat.avgConcurrency, 2));
185 CHECK (0 == stat.timeAtConc(0));
186 CHECK (0 < stat.timeAtConc(1));
187 CHECK (0 < stat.timeAtConc(2));
188 CHECK (0 == stat.timeAtConc(3));
189 CHECK (stat.timeAtConc(1) < stat.coveredTime);
190 CHECK (stat.timeAtConc(2) < stat.coveredTime);
192 CHECK (isNumEq (stat.avgConcurrency, (1*stat.timeAtConc(1) + 2*stat.timeAtConc(2))
193 / stat.coveredTime));
195 CHECK (isNumEq (stat.cumulatedTime , stat.timeCase(0) + stat.timeCase(2)));
196 CHECK (isNumEq (stat.activeTime , stat.timeThread(0) + stat.timeThread(1)));
197 CHECK (isNumEq (stat.coveredTime , stat.timeAtConc(1) + stat.timeAtConc(2)));
199 CHECK (stat.timeCase(2) < stat.timeCase(0));
200 CHECK (isNumEq (stat.coveredTime , stat.timeCase(0) - stat.timeAtConc(2)));
209 constexpr
size_t CONCURR = 16;
210 const size_t REPETITIONS = 100;
213 watch.expectThreads(CONCURR)
214 .expectIncidents(10000);
217 ,gen = makeRandGen()]
220 uint delay = 100 + gen.i(800);
222 sleep_for (microseconds(delay));
224 sleep_for (microseconds(delay));
230 auto [runTime, sum] = test::threadBenchmark<CONCURR> (act, REPETITIONS);
232 CHECK (sum == CONCURR*REPETITIONS);
233 CHECK (isLimited (900, runTime, 1400));
239 CHECK (isLimited (900*REPETITIONS, stat.coveredTime, 1400*REPETITIONS));
240 CHECK (stat.activeTime > 900 * REPETITIONS*CONCURR);
241 CHECK (stat.activationCnt == 2*REPETITIONS*CONCURR);
242 CHECK (stat.cntCase(0) == REPETITIONS*CONCURR);
243 CHECK (stat.cntCase(1) == 0);
244 CHECK (stat.cntCase(2) == REPETITIONS*CONCURR);
246 CHECK (isLimited(CONCURR/2, stat.avgConcurrency, CONCURR));
249 for (uint i=0; i<CONCURR; ++i)
250 CHECK (isLimited(REPETITIONS*900, stat.timeThread(i), REPETITIONS*1400));
252 CHECK (0 == stat.timeThread(CONCURR));
253 CHECK (0 == stat.timeAtConc(CONCURR+1));
255 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()
Simplistic 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...