1
0
mirror of https://github.com/tearshark/librf.git synced 2024-10-01 15:57:07 +08:00
librf/benchmark/benchmark_async_mem.cpp

41 lines
713 B
C++
Raw Normal View History

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-03-23 22:11:35 +08:00
const size_t N = 2000000;
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
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)
{
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;
}
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();
if (wait_key)
{
std::cout << "press any key to continue." << std::endl;
2020-03-26 17:26:39 +08:00
(void)getchar();
}
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字节