56int main(
int argc,
char *argv[]) {
57 puts(
"###################### context coroutine (stack using memory pool) ###################");
58 printf(
"########## Cmd:");
59 for (
int i = 0; i < argc; ++i) {
60 printf(
" %s", argv[i]);
72 size_t stack_size = 16 * 1024;
74 stack_size =
static_cast<size_t>(atoi(argv[3]) * 1024);
76 if (stack_size < copp::stack_traits::minimum_size()) {
77 stack_size = copp::stack_traits::minimum_size();
83 time_t begin_time = time(
nullptr);
89 time_t end_time = time(
nullptr);
91 printf(
"allocate %d coroutine, cost time: %d s, clock time: %d ms, avg: %lld ns\n",
MAX_COROUTINE_NUMBER,
92 static_cast<int>(end_time - begin_time),
CALC_MS_CLOCK(end_clock - begin_clock),
95 begin_time = end_time;
96 begin_clock = end_clock;
101 copp::allocator::stack_allocator_memory alloc(
stack_mem_pool +
static_cast<size_t>(i) * stack_size, stack_size);
105 end_time = time(
nullptr);
107 printf(
"create %d coroutine, cost time: %d s, clock time: %d ms, avg: %lld ns\n",
MAX_COROUTINE_NUMBER,
108 static_cast<int>(end_time - begin_time),
CALC_MS_CLOCK(end_clock - begin_clock),
111 begin_time = end_time;
112 begin_clock = end_clock;
120 bool continue_flag =
true;
121 long long real_switch_times =
static_cast<long long>(0);
123 while (continue_flag) {
124 continue_flag =
false;
126 if (
false ==
co_arr[i]->is_finished()) {
127 continue_flag =
true;
134 end_time = time(
nullptr);
136 printf(
"switch %d coroutine contest %lld times, cost time: %d s, clock time: %d ms, avg: %lld ns\n",
140 begin_time = end_time;
141 begin_clock = end_clock;
146 end_time = time(
nullptr);
148 printf(
"remove %d coroutine, cost time: %d s, clock time: %d ms, avg: %lld ns\n",
MAX_COROUTINE_NUMBER,
149 static_cast<int>(end_time - begin_time),
CALC_MS_CLOCK(end_clock - begin_clock),