Pārlūkot izejas kodu

新增一个channel测试项目

tags/v2.9.7
tearshark pirms 5 gadiem
vecāks
revīzija
70b706721b

+ 1
- 0
.gitignore Parādīt failu

@@ -5,3 +5,4 @@
/vs_proj/x64
/vs_proj/.vs
/vs_proj/librf.vcxproj.user
/.vs

+ 55
- 0
benchmark/benchmark_channel_passing_next.cpp Parādīt failu

@@ -0,0 +1,55 @@

#include <chrono>
#include <iostream>
#include <string>
#include <thread>
#include <deque>
#include <mutex>

#include "librf.h"

using namespace resumef;
using namespace std::chrono;
using namespace std::literals;

const static auto MaxNum = 20000;
using int_channel_ptr = std::shared_ptr<channel_t<intptr_t>>;

static future_vt passing_next(int_channel_ptr rd, int_channel_ptr wr)
{
for (;;)
{
intptr_t value = co_await *rd;
co_await (*wr << (value + 1));
}
}

void benchmark_main_channel_passing_next()
{
int_channel_ptr head = std::make_shared<channel_t<intptr_t>>(1);
int_channel_ptr in = head;
int_channel_ptr tail = nullptr;

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

GO
{
for (;;)
{
auto tstart = high_resolution_clock::now();

co_await (*head << 0);
intptr_t value = co_await *tail;

auto dt = duration_cast<duration<double>>(high_resolution_clock::now() - tstart).count();
std::cout << value << " cost time " << dt << "s" << std::endl;
}
};

this_scheduler()->run_until_notask();
}

+ 1
- 0
vs_proj/librf.vcxproj Parādīt failu

@@ -182,6 +182,7 @@
<ItemGroup>
<ClCompile Include="..\benchmark\benchmark_asio_echo.cpp" />
<ClCompile Include="..\benchmark\benchmark_async_mem.cpp" />
<ClCompile Include="..\benchmark\benchmark_channel_passing_next.cpp" />
<ClCompile Include="..\librf\src\event.cpp" />
<ClCompile Include="..\librf\src\mutex.cpp" />
<ClCompile Include="..\librf\src\rf_task.cpp" />

+ 3
- 0
vs_proj/librf.vcxproj.filters Parādīt failu

@@ -106,6 +106,9 @@
<ClCompile Include="..\tutorial\test_async_modern_cb.cpp">
<Filter>tutorial</Filter>
</ClCompile>
<ClCompile Include="..\benchmark\benchmark_channel_passing_next.cpp">
<Filter>benchmark</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\librf\librf.h">

Notiek ielāde…
Atcelt
Saglabāt