Browse Source

更新一些测试方案

tags/v2.9.7
tearshark 4 years ago
parent
commit
da9c2fa75f

+ 9
- 7
benchmark/benchmark_channel_passing_next.cpp View File

@@ -12,15 +12,17 @@ using namespace resumef;
using namespace std::chrono;
using namespace std::literals;

const static auto MaxNum = 20000;
const static auto MaxNum = 100000;
const static auto LoopCount = 100;

using int_channel_ptr = std::shared_ptr<channel_t<intptr_t>>;

static future_t<> passing_next(int_channel_ptr rd, int_channel_ptr wr)
static future_t<> passing_next(channel_t<intptr_t> rd, channel_t<intptr_t> wr)
{
for (;;)
for (int i = 0; i < LoopCount; ++i)
{
intptr_t value = co_await *rd;
co_await wr->write(value + 1);
intptr_t value = co_await rd;
co_await wr.write(value + 1);
}
}

@@ -33,13 +35,13 @@ void benchmark_main_channel_passing_next()
for (int i = 0; i < MaxNum; ++i)
{
tail = std::make_shared<channel_t<intptr_t>>(1);
go passing_next(in, tail);
go passing_next(*in, *tail);
in = tail;
}

GO
{
for (;;)
for (int i = 0; i < LoopCount; ++i)
{
auto tstart = high_resolution_clock::now();


+ 12
- 0
librf/src/scheduler.cpp View File

@@ -60,6 +60,18 @@ RESUMEF_NS
#endif
}
local_scheduler::local_scheduler(scheduler_t& sch)
{
#if RESUMEF_ENABLE_MULT_SCHEDULER
if (th_scheduler_ptr == nullptr)
{
th_scheduler_ptr = &sch;
}
_scheduler_ptr = nullptr;
#endif
}
local_scheduler::~local_scheduler()
{
#if RESUMEF_ENABLE_MULT_SCHEDULER

+ 1
- 0
librf/src/scheduler.h View File

@@ -72,6 +72,7 @@ RESUMEF_NS
struct local_scheduler
{
local_scheduler();
local_scheduler(scheduler_t & sch);
~local_scheduler();
local_scheduler(local_scheduler&& right_) = delete;

+ 2
- 2
tutorial/test_async_channel_mult_thread.cpp View File

@@ -18,7 +18,7 @@ std::atomic<intptr_t> gcounter = 0;
#define OUTPUT_DEBUG 0
future_t<> test_channel_consumer(const channel_t<std::string> & c, size_t cnt)
future_t<> test_channel_consumer(channel_t<std::string> c, size_t cnt)
{
for (size_t i = 0; i < cnt; ++i)
{
@@ -50,7 +50,7 @@ future_t<> test_channel_consumer(const channel_t<std::string> & c, size_t cnt)
}
}
future_t<> test_channel_producer(const channel_t<std::string> & c, size_t cnt)
future_t<> test_channel_producer(channel_t<std::string> c, size_t cnt)
{
for (size_t i = 0; i < cnt; ++i)
{

+ 2
- 2
tutorial/test_async_switch_scheduler.cpp View File

@@ -12,7 +12,7 @@ using namespace resumef;
static scheduler_t* sch_in_main = nullptr;
static std::atomic<scheduler_t*> sch_in_thread = nullptr;

void run_in_thread(channel_t<bool>& c_done)
void run_in_thread(channel_t<bool> c_done)
{
std::cout << "other thread = " << std::this_thread::get_id() << std::endl;

@@ -55,7 +55,7 @@ static future_t<int64_t> async_get_long(int64_t val)
}

//这种情况下,会生成对应的 frame-context,一个promise_type被内嵌在frame-context里
static future_t<> resumable_get_long(int64_t val, channel_t<bool> & c_done)
static future_t<> resumable_get_long(int64_t val, channel_t<bool> c_done)
{
std::cout << "thread = " << std::this_thread::get_id() << ", value = " << val << std::endl;


Loading…
Cancel
Save