Browse Source

更新一些测试方案

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

+ 9
- 7
benchmark/benchmark_channel_passing_next.cpp View File

using namespace std::chrono; using namespace std::chrono;
using namespace std::literals; 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>>; 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);
} }
} }


for (int i = 0; i < MaxNum; ++i) for (int i = 0; i < MaxNum; ++i)
{ {
tail = std::make_shared<channel_t<intptr_t>>(1); tail = std::make_shared<channel_t<intptr_t>>(1);
go passing_next(in, tail);
go passing_next(*in, *tail);
in = tail; in = tail;
} }


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



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

#endif #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() local_scheduler::~local_scheduler()
{ {
#if RESUMEF_ENABLE_MULT_SCHEDULER #if RESUMEF_ENABLE_MULT_SCHEDULER

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

struct local_scheduler struct local_scheduler
{ {
local_scheduler(); local_scheduler();
local_scheduler(scheduler_t & sch);
~local_scheduler(); ~local_scheduler();
local_scheduler(local_scheduler&& right_) = delete; local_scheduler(local_scheduler&& right_) = delete;

+ 2
- 2
tutorial/test_async_channel_mult_thread.cpp View File

#define OUTPUT_DEBUG 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) for (size_t i = 0; i < cnt; ++i)
{ {
} }
} }
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) for (size_t i = 0; i < cnt; ++i)
{ {

+ 2
- 2
tutorial/test_async_switch_scheduler.cpp View File

static scheduler_t* sch_in_main = nullptr; static scheduler_t* sch_in_main = nullptr;
static std::atomic<scheduler_t*> sch_in_thread = 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; std::cout << "other thread = " << std::this_thread::get_id() << std::endl;


} }


//这种情况下,会生成对应的 frame-context,一个promise_type被内嵌在frame-context里 //这种情况下,会生成对应的 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; std::cout << "thread = " << std::this_thread::get_id() << ", value = " << val << std::endl;



Loading…
Cancel
Save