基于C++ Coroutines提案 ‘Stackless Resumable Functions’编写的协程库
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

benchmark_async_mem.cpp 643B

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