add benchmark to app. TODO: test benchmark.

This commit is contained in:
TXuian 2022-12-07 16:21:19 +08:00
parent eee22c91ce
commit 88f42626a3
2 changed files with 12 additions and 8 deletions

View File

@ -64,7 +64,7 @@ BenchmarkPair bmh_list[] = {
float benchmark_time[25]; float benchmark_time[25];
extern benchmark_handle *get_benchmark_list(); extern benchmark_handle *get_benchmark_list();
extern void add_benchmark_handle(benchmark_handle *); extern void add_benchmark_handle(benchmark_handle *head, benchmark_handle *);
int store_idx = 0; int store_idx = 0;
float tmp_diff = 0.0; float tmp_diff = 0.0;
@ -74,10 +74,10 @@ clock_t start_time = 0, end_time = 0;
void start_trigger(void) { start_time = PrivGetTickTime(); } void start_trigger(void) { start_time = PrivGetTickTime(); }
void stop_trigger(void) { end_time = PrivGetTickTime(); } void stop_trigger(void) { end_time = PrivGetTickTime(); }
void init_benchmark_runset() { void init_benchmark_runset(benchmark_handle *head) {
int i = 0; int i = 0;
while (bmh_list[i].handle != NULL) { while (bmh_list[i].handle != NULL) {
add_benchmark_handle(bmh_list[i++].handle); add_benchmark_handle(head, bmh_list[i++].handle);
} }
} }
void organize_result(const benchmark_handle *handle) { void organize_result(const benchmark_handle *handle) {
@ -107,10 +107,14 @@ int run_benchmark() {
volatile int result; volatile int result;
int correct; int correct;
init_benchmark_runset(); benchmark_handle head = {
.handle.magic_number = MAGIC_NUMBER,
.next = NULL,
};
init_benchmark_runset(&head);
printf("[BENCHMARK] Start Benchmark running.\n"); printf("[BENCHMARK] Start Benchmark running.\n");
benchmark_handle *cur_handle = get_benchmark_list()->next; benchmark_handle *cur_handle = head.next;
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();

View File

@ -90,7 +90,7 @@ static benchmark_handle *get_benchmark_list() {
return &head; return &head;
} }
static void add_benchmark_handle(benchmark_handle *bh) { static void add_benchmark_handle(benchmark_handle *head, benchmark_handle *bh) {
if (NULL == bh) { if (NULL == bh) {
return; return;
} }
@ -102,8 +102,8 @@ static void add_benchmark_handle(benchmark_handle *bh) {
NULL == bh->handle.benchmark_func->verify_benchmark) { NULL == bh->handle.benchmark_func->verify_benchmark) {
return; return;
} }
bh->next = get_benchmark_list()->next; bh->next = head->next;
get_benchmark_list()->next = bh; head->next = bh;
} }
/* Local simplified versions of library functions */ /* Local simplified versions of library functions */