MCPcopy Create free account
hub / github.com/catboost/catboost / TEST_Concurrent

Method TEST_Concurrent

library/cpp/threading/skip_list/perf/main.cpp:287–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285 }
286
287 void TEST_Concurrent() {
288 LogInfo() << "starting producers..." << Endl;
289
290 TVector<TAutoPtr<TWorkerThread>> producers(NumWriters);
291 for (size_t i1 = 0; i1 < producers.size(); ++i1) {
292 producers[i1] = StartThread([&] {
293 TInstant started = TInstant::Now();
294 for (size_t i2 = 0; i2 < Iterations; ++i2) {
295 {
296 TGuard<TMutex> guard(Mutex);
297 List.Insert(TListItem(Random.GetString(KeyLen), Random.GetString(ValueLen)));
298 }
299 }
300 TDuration duration = TInstant::Now() - started;
301 LogInfo()
302 << "Average time for producer = "
303 << (double)duration.MicroSeconds() / Iterations << "us per iteration"
304 << Endl;
305 });
306 }
307
308 LogInfo() << "starting consumers..." << Endl;
309
310 TVector<TAutoPtr<TWorkerThread>> consumers(NumReaders);
311 for (size_t i1 = 0; i1 < consumers.size(); ++i1) {
312 consumers[i1] = StartThread([&] {
313 TInstant started = TInstant::Now();
314 for (size_t i2 = 0; i2 < Iterations; ++i2) {
315 List.SeekTo(TListItem(Random.GetString(KeyLen), TStringBuf()));
316 }
317 TDuration duration = TInstant::Now() - started;
318 LogInfo()
319 << "Average time for consumer = "
320 << (double)duration.MicroSeconds() / Iterations << "us per iteration"
321 << Endl;
322 });
323 }
324
325 LogInfo() << "wait for producers..." << Endl;
326
327 TDuration producerTime;
328 for (size_t i = 0; i < producers.size(); ++i) {
329 producers[i]->Join();
330 producerTime += producers[i]->GetTime();
331 }
332
333 LogInfo() << "wait for consumers..." << Endl;
334
335 TDuration consumerTime;
336 for (size_t i = 0; i < consumers.size(); ++i) {
337 consumers[i]->Join();
338 consumerTime += consumers[i]->GetTime();
339 }
340
341 LogInfo() << "average producer time: "
342 << producerTime.SecondsFloat() / producers.size() << " seconds"
343 << Endl;
344

Callers

nothing calls this directly

Calls 11

StartThreadFunction · 0.85
TListItemClass · 0.85
SeekToMethod · 0.80
SecondsFloatMethod · 0.80
NowFunction · 0.50
sizeMethod · 0.45
InsertMethod · 0.45
GetStringMethod · 0.45
MicroSecondsMethod · 0.45
JoinMethod · 0.45
GetTimeMethod · 0.45

Tested by

no test coverage detected