File tree Expand file tree Collapse file tree 4 files changed +60
-0
lines changed Expand file tree Collapse file tree 4 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 5
5
/vs_proj /x64
6
6
/vs_proj /.vs
7
7
/vs_proj /librf.vcxproj.user
8
+ /.vs
Original file line number Diff line number Diff line change
1
+
2
+ #include < chrono>
3
+ #include < iostream>
4
+ #include < string>
5
+ #include < thread>
6
+ #include < deque>
7
+ #include < mutex>
8
+
9
+ #include " librf.h"
10
+
11
+ using namespace resumef ;
12
+ using namespace std ::chrono;
13
+ using namespace std ::literals;
14
+
15
+ const static auto MaxNum = 20000 ;
16
+ using int_channel_ptr = std::shared_ptr<channel_t <intptr_t >>;
17
+
18
+ static future_vt passing_next (int_channel_ptr rd, int_channel_ptr wr)
19
+ {
20
+ for (;;)
21
+ {
22
+ intptr_t value = co_await *rd;
23
+ co_await (*wr << (value + 1 ));
24
+ }
25
+ }
26
+
27
+ void benchmark_main_channel_passing_next ()
28
+ {
29
+ int_channel_ptr head = std::make_shared<channel_t <intptr_t >>(1 );
30
+ int_channel_ptr in = head;
31
+ int_channel_ptr tail = nullptr ;
32
+
33
+ for (int i = 0 ; i < MaxNum; ++i)
34
+ {
35
+ tail = std::make_shared<channel_t <intptr_t >>(1 );
36
+ go passing_next (in, tail);
37
+ in = tail;
38
+ }
39
+
40
+ GO
41
+ {
42
+ for (;;)
43
+ {
44
+ auto tstart = high_resolution_clock::now ();
45
+
46
+ co_await (*head << 0 );
47
+ intptr_t value = co_await *tail;
48
+
49
+ auto dt = duration_cast<duration<double >>(high_resolution_clock::now () - tstart).count ();
50
+ std::cout << value << " cost time " << dt << " s" << std::endl;
51
+ }
52
+ };
53
+
54
+ this_scheduler ()->run_until_notask ();
55
+ }
Original file line number Diff line number Diff line change 182
182
<ItemGroup >
183
183
<ClCompile Include =" ..\benchmark\benchmark_asio_echo.cpp" />
184
184
<ClCompile Include =" ..\benchmark\benchmark_async_mem.cpp" />
185
+ <ClCompile Include =" ..\benchmark\benchmark_channel_passing_next.cpp" />
185
186
<ClCompile Include =" ..\librf\src\event.cpp" />
186
187
<ClCompile Include =" ..\librf\src\mutex.cpp" />
187
188
<ClCompile Include =" ..\librf\src\rf_task.cpp" />
Original file line number Diff line number Diff line change 106
106
<ClCompile Include =" ..\tutorial\test_async_modern_cb.cpp" >
107
107
<Filter >tutorial</Filter >
108
108
</ClCompile >
109
+ <ClCompile Include =" ..\benchmark\benchmark_channel_passing_next.cpp" >
110
+ <Filter >benchmark</Filter >
111
+ </ClCompile >
109
112
</ItemGroup >
110
113
<ItemGroup >
111
114
<ClInclude Include =" ..\librf\librf.h" >
You can’t perform that action at this time.
0 commit comments