Add Benchmark Sequential
This commit is contained in:
parent
c5acbb1ca9
commit
5549eb0271
|
@ -1,5 +1,3 @@
|
||||||
#ifndef _BENCHMARK_H_
|
|
||||||
#define _BENCHMARK_H_
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -105,9 +103,13 @@ void print_result() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *print_result_asyn(void *g_start_time) {
|
struct wrap_time {
|
||||||
|
clock_t time;
|
||||||
|
};
|
||||||
|
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,
|
||||||
|
@ -115,13 +117,11 @@ void *print_result_asyn(void *g_start_time) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
printf("[BENCHMARK] Global Time Diff: %f\n",
|
printf("[BENCHMARK] Global Time Diff: %f\n",
|
||||||
(float)((g_stop_time - *(clock_t *)g_start_time) /
|
(float)((g_stop_time - start_wt->time) / (10 * TICK_PER_SECOND)));
|
||||||
(10 * TICK_PER_SECOND)));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int done_cnt = 0;
|
int done_cnt = 0;
|
||||||
pthread_mutex_t case_mu;
|
pthread_mutex_t case_mu;
|
||||||
sem_t syn_sem;
|
|
||||||
void *run_one_example(void *arg) {
|
void *run_one_example(void *arg) {
|
||||||
const benchmark_handle *handle = arg;
|
const benchmark_handle *handle = arg;
|
||||||
assert(handle != NULL);
|
assert(handle != NULL);
|
||||||
|
@ -140,8 +140,6 @@ void *run_one_example(void *arg) {
|
||||||
PrivMutexObtain(&case_mu);
|
PrivMutexObtain(&case_mu);
|
||||||
organize_result(handle, start_time, end_time);
|
organize_result(handle, start_time, end_time);
|
||||||
PrivMutexAbandon(&case_mu);
|
PrivMutexAbandon(&case_mu);
|
||||||
PrivSemaphoreAbandon(&syn_sem);
|
|
||||||
done_cnt++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_attr_t case_attr;
|
pthread_attr_t case_attr;
|
||||||
|
@ -165,8 +163,9 @@ void *run_benchmark_parallel(void *args) {
|
||||||
|
|
||||||
benchmark_handle *cur_handle = head.next;
|
benchmark_handle *cur_handle = head.next;
|
||||||
|
|
||||||
clock_t g_start_time = 0;
|
// 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,
|
||||||
|
@ -178,7 +177,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,
|
||||||
(void *)&g_start_time);
|
(void *)&start_time);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,5 +239,3 @@ PRIV_SHELL_CMD_FUNCTION(embenchmark_parallel, run benchmark in parallel,
|
||||||
PRIV_SHELL_CMD_MAIN_ATTR);
|
PRIV_SHELL_CMD_MAIN_ATTR);
|
||||||
PRIV_SHELL_CMD_FUNCTION(embenchmark_sequential, run benchmark in sequential,
|
PRIV_SHELL_CMD_FUNCTION(embenchmark_sequential, run benchmark in sequential,
|
||||||
PRIV_SHELL_CMD_MAIN_ATTR);
|
PRIV_SHELL_CMD_MAIN_ATTR);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
Loading…
Reference in New Issue