| 345 | |
| 346 | int DevNull(void*, int); |
| 347 | void 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 | |
| 379 | TEST(Perf, ThreadSwitch) |
| 380 | { |
no test coverage detected