基于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 540B

123456789101112131415161718192021222324252627282930313233
  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. for (size_t i = 0; i < N; ++i)
  13. {
  14. go[=]()->resumef::generator_t<size_t>
  15. {
  16. for (size_t k = 0; k < 10; ++k)
  17. {
  18. globalValue += i * k;
  19. co_yield k;
  20. }
  21. co_return 0;
  22. };
  23. }
  24. resumef::this_scheduler()->run_until_notask();
  25. (void)_getch();
  26. }