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

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 = 10000000;
  9. const size_t LOOP_COUNT = 100;
  10. volatile size_t globalValue = 0;
  11. void resumable_main_benchmark_mem(bool wait_key)
  12. {
  13. using namespace std::chrono;
  14. for (size_t i = 0; i < N; ++i)
  15. {
  16. go[=]()->resumef::generator_t<size_t>
  17. {
  18. for (size_t k = 0; k < LOOP_COUNT; ++k)
  19. {
  20. globalValue += i * k;
  21. co_yield k;
  22. }
  23. co_return 0;
  24. };
  25. }
  26. resumef::this_scheduler()->run_until_notask();
  27. if (wait_key)
  28. {
  29. std::cout << "press any key to continue." << std::endl;
  30. (void)_getch();
  31. }
  32. }
  33. //clang : 平均 210字节
  34. //msvc : 平均600字节