2020-03-26 17:26:39 +08:00
|
|
|
|
2017-09-24 14:36:36 +08:00
|
|
|
#include <chrono>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
#include "librf.h"
|
|
|
|
|
2020-05-10 11:11:49 +08:00
|
|
|
const size_t N = 5000000;
|
2020-03-18 21:59:36 +08:00
|
|
|
const size_t LOOP_COUNT = 50;
|
2017-09-24 14:36:36 +08:00
|
|
|
|
2020-04-18 11:46:29 +08:00
|
|
|
std::atomic<size_t> globalValue{0};
|
2018-08-08 21:01:25 +08:00
|
|
|
|
2020-03-02 14:50:01 +08:00
|
|
|
void resumable_main_benchmark_mem(bool wait_key)
|
2017-09-24 14:36:36 +08:00
|
|
|
{
|
|
|
|
using namespace std::chrono;
|
2018-08-08 21:01:25 +08:00
|
|
|
|
2017-09-24 14:36:36 +08:00
|
|
|
for (size_t i = 0; i < N; ++i)
|
|
|
|
{
|
2020-02-29 01:11:21 +08:00
|
|
|
go[=]()->resumef::generator_t<size_t>
|
2017-09-24 14:36:36 +08:00
|
|
|
{
|
2020-03-01 13:17:04 +08:00
|
|
|
for (size_t k = 0; k < LOOP_COUNT; ++k)
|
2018-08-08 21:01:25 +08:00
|
|
|
{
|
|
|
|
globalValue += i * k;
|
|
|
|
co_yield k;
|
|
|
|
}
|
2020-02-16 12:49:58 +08:00
|
|
|
co_return 0;
|
2017-09-24 14:36:36 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-10-01 10:33:08 +08:00
|
|
|
resumef::this_scheduler()->run_until_notask();
|
2020-03-02 14:50:01 +08:00
|
|
|
if (wait_key)
|
|
|
|
{
|
|
|
|
std::cout << "press any key to continue." << std::endl;
|
2020-03-26 17:26:39 +08:00
|
|
|
(void)getchar();
|
2020-03-02 14:50:01 +08:00
|
|
|
}
|
2017-09-24 14:36:36 +08:00
|
|
|
}
|
2020-03-01 15:38:05 +08:00
|
|
|
|
|
|
|
//clang : 平均 210字节
|
2020-03-26 17:26:39 +08:00
|
|
|
//msvc : 平均600字节
|