Browse Source

改善协程切换测试代码

tags/v2.9.7
tearshark 4 years ago
parent
commit
6c659d57e2
2 changed files with 17 additions and 12 deletions
  1. 16
    11
      tutorial/test_async_resumable.cpp
  2. 1
    1
      vs_proj/librf.cpp

+ 16
- 11
tutorial/test_async_resumable.cpp View File

#include "librf.h" #include "librf.h"
static const intptr_t N = 10000000;
//static const int N = 10;
static std::mutex lock_console; static std::mutex lock_console;
template <typename T> template <typename T>
void dump(size_t idx, std::string name, T start, T end)
void dump(size_t idx, std::string name, T start, T end, intptr_t count)
{ {
lock_console.lock(); lock_console.lock();
auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count(); auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
std::cout << idx << ":" << name << " "; std::cout << idx << ":" << name << " ";
std::cout << N << " " << ns << " ns ";
std::cout << (ns / N) << " ns/op" << " ";
std::cout << (N * 100ll * 1000ll / ns) << "w/cps" << std::endl;
std::cout << count << " " << ns << " ns ";
std::cout << (ns / count) << " ns/op" << " ";
std::cout << (count * 100ll * 1000ll / ns) << "w/cps" << std::endl;
lock_console.unlock(); lock_console.unlock();
} }
static const intptr_t N = 3000000;
//static const int N = 10;
auto yield_switch(intptr_t coro) auto yield_switch(intptr_t coro)
{ {
for (intptr_t i = 0; i < N / coro; ++i) for (intptr_t i = 0; i < N / coro; ++i)
return N / coro; return N / coro;
}; };
} }
auto middle = std::chrono::steady_clock::now();
dump(idx, "BenchmarkCreate_" + std::to_string(coro), start, middle, coro);
resumef::this_scheduler()->run_until_notask(); resumef::this_scheduler()->run_until_notask();
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
dump(idx, "BenchmarkSwitch_" + std::to_string(coro), start, end);
dump(idx, "BenchmarkSwitch_" + std::to_string(coro), middle, end, N);
} }
void resumable_main_resumable() void resumable_main_resumable()
{ {
//resumable_switch(1, 0);
resumable_switch(1, 0);
//resumable_switch(10, 0); //resumable_switch(10, 0);
//resumable_switch(100, 0); //resumable_switch(100, 0);
//resumable_switch(10000, 0);
//resumable_switch(10000000, 0);
resumable_switch(1000, 0);
resumable_switch(30000, 0);
/*
std::thread works[32]; std::thread works[32];
for (size_t w = 1; w <= _countof(works); ++w) for (size_t w = 1; w <= _countof(works); ++w)
{ {
std::cout << std::endl << std::endl; std::cout << std::endl << std::endl;
} }
*/
} }

+ 1
- 1
vs_proj/librf.cpp View File

int main(int argc, const char* argv[]) int main(int argc, const char* argv[])
{ {
resumable_main_modern_cb();
resumable_main_resumable();
//resumable_main_benchmark_mem(); //resumable_main_benchmark_mem();
/* /*
if (argc > 1) if (argc > 1)

Loading…
Cancel
Save