Add Benchmark Sequential

This commit is contained in:
TXuian 2022-12-09 22:52:46 +08:00
parent a6cfd4952a
commit 73a2917ba3
1 changed files with 17 additions and 7 deletions

View File

@ -96,7 +96,18 @@ void organize_result(const benchmark_handle *handle, clock_t start_time,
} }
} }
void *print_result(void *g_time_diff) { void print_result() {
int i = 0;
while (bmh_list[i].handle != NULL) {
printf("[BENCHMARK] Time Cost: %-15s %.4f\n", bmh_list[i].name,
bmh_list[i].time);
i++;
}
}
void *print_result_asyn(void *g_start_time) {
clock_t g_stop_time = 0;
stop_trigger(&g_stop_time);
int i = 0; int i = 0;
while (bmh_list[i].handle != NULL) { while (bmh_list[i].handle != NULL) {
printf("[BENCHMARK] Time Cost: %-15s %.4f\n", bmh_list[i].name, printf("[BENCHMARK] Time Cost: %-15s %.4f\n", bmh_list[i].name,
@ -104,7 +115,8 @@ void *print_result(void *g_time_diff) {
i++; i++;
} }
printf("[BENCHMARK] Global Time Diff: %f\n", printf("[BENCHMARK] Global Time Diff: %f\n",
(float)(*(clock_t *)g_time_diff / (10 * TICK_PER_SECOND))); (float)((g_stop_time - *(clock_t *)g_start_time) /
(10 * TICK_PER_SECOND)));
}; };
int done_cnt = 0; int done_cnt = 0;
@ -153,7 +165,7 @@ void *run_benchmark_parallel(void *args) {
benchmark_handle *cur_handle = head.next; benchmark_handle *cur_handle = head.next;
clock_t g_start_time = 0, g_stop_time = 0; clock_t g_start_time = 0;
start_trigger(&g_start_time); start_trigger(&g_start_time);
while (NULL != cur_handle) { while (NULL != cur_handle) {
assert(cur_handle->handle.magic_number != MAGIC_NUMBER); assert(cur_handle->handle.magic_number != MAGIC_NUMBER);
@ -162,12 +174,10 @@ void *run_benchmark_parallel(void *args) {
cur_handle = cur_handle->next; cur_handle = cur_handle->next;
} }
stop_trigger(&g_stop_time);
clock_t g_time_diff = g_stop_time - g_start_time;
case_attr.schedparam.sched_priority = 23; case_attr.schedparam.sched_priority = 23;
case_attr.stacksize = 4096; case_attr.stacksize = 4096;
PrivTaskCreate(&res_thread, &case_attr, print_result, &g_time_diff); PrivTaskCreate(&res_thread, &case_attr, print_result_asyn, &g_start_time);
return NULL; return NULL;
} }
@ -206,7 +216,7 @@ void *run_benchmark_sequential(void *args) {
stop_trigger(&g_stop_time); stop_trigger(&g_stop_time);
clock_t g_time_diff = g_stop_time - g_start_time; clock_t g_time_diff = g_stop_time - g_start_time;
print_result(&g_time_diff); print_result();
printf("[BENCHMARK] Global Time Diff: %f\n", printf("[BENCHMARK] Global Time Diff: %f\n",
(float)((g_stop_time - g_start_time) / (10 * TICK_PER_SECOND))); (float)((g_stop_time - g_start_time) / (10 * TICK_PER_SECOND)));
} }