53int main(
int argc,
char *argv[]) {
54 puts(
"###################### context coroutine (stack using malloc/free) ###################");
55 printf(
"########## Cmd:");
56 for (
int i = 0; i < argc; ++i) {
57 printf(
" %s", argv[i]);
69 size_t stack_size = 16 * 1024;
71 stack_size =
static_cast<size_t>(atoi(argv[3]) * 1024);
73 if (stack_size < copp::stack_traits::minimum_size()) {
74 stack_size = copp::stack_traits::minimum_size();
77 time_t begin_time = time(
nullptr);
83 time_t end_time = time(
nullptr);
85 printf(
"allocate %d coroutine, cost time: %d s, clock time: %d ms, avg: %lld ns\n",
MAX_COROUTINE_NUMBER,
86 static_cast<int>(end_time - begin_time),
CALC_MS_CLOCK(end_clock - begin_clock),
95 end_time = time(
nullptr);
97 printf(
"create %d coroutine, cost time: %d s, clock time: %d ms, avg: %lld ns\n",
MAX_COROUTINE_NUMBER,
98 static_cast<int>(end_time - begin_time),
CALC_MS_CLOCK(end_clock - begin_clock),
101 begin_time = end_time;
102 begin_clock = end_clock;
110 bool continue_flag =
true;
111 long long real_switch_times =
static_cast<long long>(0);
113 while (continue_flag) {
114 continue_flag =
false;
116 if (
false ==
co_arr[i]->is_finished()) {
117 continue_flag =
true;
124 end_time = time(
nullptr);
126 printf(
"switch %d coroutine contest %lld times, cost time: %d s, clock time: %d ms, avg: %lld ns\n",
130 begin_time = end_time;
131 begin_clock = end_clock;
135 end_time = time(
nullptr);
137 printf(
"remove %d coroutine, cost time: %d s, clock time: %d ms, avg: %lld ns\n",
MAX_COROUTINE_NUMBER,
138 static_cast<int>(end_time - begin_time),
CALC_MS_CLOCK(end_clock - begin_clock),