基于C++ Coroutines提案 ‘Stackless Resumable Functions’编写的协程库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

benchmark_async_mem.cpp 637B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <chrono>
  2. #include <iostream>
  3. #include <string>
  4. #include <conio.h>
  5. #include <thread>
  6. #include "librf.h"
  7. const size_t N = 1000000;
  8. volatile size_t globalValue = 0;
  9. void resumable_main_benchmark_mem()
  10. {
  11. using namespace std::chrono;
  12. resumef::state_t<void> st;
  13. std::cout << sizeof(st) << " " << sizeof(resumef::promise_vt) << std::endl;
  14. for (size_t i = 0; i < N; ++i)
  15. {
  16. go[=]()->resumef::future_t<size_t>
  17. {
  18. for (size_t k = 0; k < 10; ++k)
  19. {
  20. globalValue += i * k;
  21. co_yield k;
  22. }
  23. return 0;
  24. };
  25. }
  26. resumef::this_scheduler()->run_until_notask();
  27. _getch();
  28. }