MCPcopy Create free account
hub / github.com/alibaba/PhotonLibOS / test_thread_switch

Function test_thread_switch

thread/test/test.cpp:347–377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

345
346int DevNull(void*, int);
347void test_thread_switch(uint64_t nth, uint64_t stack_size)
348{
349 const uint64_t total = 100*1000*1000;
350 uint64_t count = total / nth;
351
352 for (uint64_t i = 0; i < nth - 2; ++i)
353 photon::thread_create(&thread_pong, (void*)(uint64_t)(rand() % 32), stack_size);
354
355 for (uint64_t i = 0; i < count; ++i)
356 thread_yield_fast();
357
358 auto t0 = now_time();
359 for (uint64_t i = 0; i < count; ++i)
360 thread_yield_fast();
361
362 auto t1 = now_time();
363
364 for (uint64_t i = 0; i < count; ++i)
365 DevNull(&i, 0);
366
367 auto t2 = now_time();
368
369 auto d1 = t1 - t0;
370 auto d2 = (t2 - t1) * nth;
371 LOG_INFO("threads `, stack-size `, time `, loop time `, ", nth, stack_size, d1, d2);
372 LOG_INFO("single context switch: ` ns (` M/s)",
373 double((d1 - d2)*1000) / total, total / double(d1 - d2));
374
375 running = 0;
376 wait_for_completion();
377}
378
379TEST(Perf, ThreadSwitch)
380{

Callers 1

TESTFunction · 0.85

Calls 5

thread_createFunction · 0.85
thread_yield_fastFunction · 0.85
now_timeFunction · 0.70
DevNullFunction · 0.70
wait_for_completionFunction · 0.70

Tested by

no test coverage detected