Add Benchmark Sequential

This commit is contained in:
TXuian 2022-12-09 23:18:14 +08:00
parent 0c625edba5
commit 4bbda86520
1 changed files with 9 additions and 16 deletions

View File

@ -103,13 +103,10 @@ void print_result() {
} }
} }
struct wrap_time { clock_t g_start_time;
clock_t time; void *print_result_asyn() {
};
void *print_result_asyn(void *start_time) {
clock_t g_stop_time = 0; clock_t g_stop_time = 0;
stop_trigger(&g_stop_time); stop_trigger(&g_stop_time);
struct wrap_time *start_wt = (struct wrap_time *)start_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,
@ -117,7 +114,7 @@ void *print_result_asyn(void *start_time) {
i++; i++;
} }
printf("[BENCHMARK] Global Time Diff: %f\n", printf("[BENCHMARK] Global Time Diff: %f\n",
(float)((g_stop_time - start_wt->time) / (10 * TICK_PER_SECOND))); (float)((g_stop_time - g_start_time) / (10 * TICK_PER_SECOND)));
}; };
int done_cnt = 0; int done_cnt = 0;
@ -162,9 +159,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; start_trigger(&g_start_time);
struct wrap_time start_time;
start_trigger(&start_time.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);
PrivTaskCreate(&cur_handle->task_ptr, &case_attr, run_one_example, PrivTaskCreate(&cur_handle->task_ptr, &case_attr, run_one_example,
@ -175,8 +170,7 @@ void *run_benchmark_parallel(void *args) {
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_asyn, PrivTaskCreate(&res_thread, &case_attr, print_result_asyn, NULL);
(void *)&start_time);
return NULL; return NULL;
} }
@ -192,10 +186,10 @@ void *run_benchmark_sequential(void *args) {
printf("[BENCHMARK] Start Benchmark running sequential.\n"); printf("[BENCHMARK] Start Benchmark running sequential.\n");
benchmark_handle *cur_handle = head.next; benchmark_handle *cur_handle = head.next;
clock_t g_start_time = 0, g_stop_time = 0; clock_t s_start_time = 0, s_stop_time = 0;
clock_t start_time = 0, end_time = 0; clock_t start_time = 0, end_time = 0;
start_trigger(&g_start_time); start_trigger(&s_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);
cur_handle->handle.benchmark_func->initialise_benchmark(); cur_handle->handle.benchmark_func->initialise_benchmark();
@ -212,12 +206,11 @@ void *run_benchmark_sequential(void *args) {
cur_handle = cur_handle->next; cur_handle = cur_handle->next;
} }
stop_trigger(&g_stop_time); stop_trigger(&s_stop_time);
clock_t g_time_diff = g_stop_time - g_start_time;
print_result(); 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)((s_stop_time - s_start_time) / (10 * TICK_PER_SECOND)));
} }
pthread_t main_thread; pthread_t main_thread;