-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: John Sanpe <[email protected]>
- Loading branch information
Showing
5 changed files
with
87 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
# Copyright(c) 2023 ffashion <[email protected]> | ||
# | ||
|
||
add_executable(benchmark main.c rbtree.c) | ||
add_executable(benchmark main.c crc.c rbtree.c) | ||
target_link_libraries(benchmark ${CMAKE_PROJECT_NAME}) | ||
target_link_libraries(benchmark bfdev) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/* | ||
* Copyright(c) 2021-2022 John Sanpe <[email protected]> | ||
*/ | ||
|
||
#define MODULE_NAME "crc-benchmark" | ||
#define bfdev_log_fmt(fmt) MODULE_NAME ": " fmt | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <errno.h> | ||
#include <bfdev/crc.h> | ||
#include <bfdev/prandom.h> | ||
#include <bfdev/log.h> | ||
#include <bfdev/size.h> | ||
#include "py32f0xx_hal.h" | ||
|
||
#define TEST_SIZE BFDEV_SZ_1KiB | ||
#define TEST_LOOP 3 | ||
|
||
#define GENERIC_CRC_BANDWIDTH(func, name, size) \ | ||
for (count = 0; count < TEST_LOOP; ++count) { \ | ||
uint32_t start = HAL_GetTick(); \ | ||
loop = 0; \ | ||
do { \ | ||
func(buff, size, 0); \ | ||
loop++; \ | ||
} while (start + 1000 > HAL_GetTick()); \ | ||
bfdev_log_notice( \ | ||
name " bandwidth %u: %uKiB/s\n", \ | ||
count, loop \ | ||
); \ | ||
} | ||
|
||
int crc_benchmark(int argc, char const *argv[]) | ||
{ | ||
bfdev_prandom_state_t pstate; | ||
unsigned int count, loop; | ||
uint8_t *buff; | ||
size_t index; | ||
|
||
buff = malloc(TEST_SIZE); | ||
if (!buff) | ||
return 1; | ||
|
||
bfdev_prandom_seed(&pstate, HAL_GetTick()); | ||
for (count = 0; count < TEST_SIZE; ++count) | ||
buff[count] = bfdev_prandom_value(&pstate); | ||
|
||
GENERIC_CRC_BANDWIDTH(bfdev_crc7, "crc7", TEST_SIZE) | ||
GENERIC_CRC_BANDWIDTH(bfdev_crc8, "crc8", TEST_SIZE) | ||
free(buff); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
#include <stdio.h> | ||
#include <bfdev/config.h> | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/* | ||
* Copyright(c) 2021-2022 John Sanpe <[email protected]> | ||
*/ | ||
|
||
#define MODULE_NAME "benchmark" | ||
#define bfdev_log_fmt(fmt) MODULE_NAME ": " fmt | ||
|
||
#include <bfdev/log.h> | ||
#include "py32f0xx_hal.h" | ||
|
||
UART_HandleTypeDef huart1; | ||
extern int benchmark(void); | ||
extern int crc_benchmark(void); | ||
extern int rbtree_benchmark(void); | ||
|
||
int __io_putchar(int ch) | ||
{ | ||
|
@@ -49,10 +57,15 @@ int main(void) | |
__HAL_RCC_USART1_CLK_ENABLE(); | ||
HAL_UART_Init(&huart1); | ||
|
||
printf("Benchmark for PY32F0xx.\n"); | ||
printf("Bfdev version: %s\n", __bfdev_stringify(BFDEV_VERSION)); | ||
printf("This may take a few minutes...\n\n"); | ||
benchmark(); | ||
bfdev_log_info("Benchmark for PY32F0xx.\n"); | ||
bfdev_log_info("Bfdev version: %s\n", __bfdev_stringify(BFDEV_VERSION)); | ||
bfdev_log_info("This may take a few minutes...\n"); | ||
|
||
puts(""); /* '\n' */ | ||
crc_benchmark(); | ||
|
||
puts(""); /* '\n' */ | ||
rbtree_benchmark(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,15 @@ | |
* Copyright(c) 2021-2022 John Sanpe <[email protected]> | ||
*/ | ||
|
||
#define MODULE_NAME "rbtree-benchmark" | ||
#define bfdev_log_fmt(fmt) MODULE_NAME ": " fmt | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <errno.h> | ||
#include <bfdev/rbtree.h> | ||
#include <bfdev/log.h> | ||
#include "py32f0xx_hal.h" | ||
|
||
#define TEST_LEN 50 | ||
|
@@ -31,7 +35,7 @@ demo_cmp(const struct bfdev_rb_node *a, | |
return demo_a->data - demo_b->data; | ||
} | ||
|
||
int benchmark(void) | ||
int rbtree_benchmark(void) | ||
{ | ||
struct bench_node *node; | ||
unsigned int count, loop; | ||
|
@@ -40,15 +44,15 @@ int benchmark(void) | |
|
||
node = block = malloc(sizeof(*node) * TEST_LEN); | ||
if (!block) { | ||
printf("Insufficient Memory!\n"); | ||
bfdev_log_err("Insufficient Memory!\n"); | ||
return -ENOMEM; | ||
} | ||
|
||
printf("Generate Node: %u\n", TEST_LEN); | ||
bfdev_log_notice("Generate Node: %u\n", TEST_LEN); | ||
for (count = 0; count < TEST_LEN; ++count) | ||
node[count].data = count; | ||
|
||
printf("Insert Nodes: %u\n", TEST_LOOP * TEST_LEN); | ||
bfdev_log_notice("Insert Nodes: %u\n", TEST_LOOP * TEST_LEN); | ||
start = HAL_GetTick(); | ||
|
||
for (loop = 0; loop < TEST_LOOP; ++loop) { | ||
|
@@ -58,7 +62,7 @@ int benchmark(void) | |
} | ||
|
||
time = HAL_GetTick() - start; | ||
printf("Total time: %lu.%lus\n", time / 1000, time % 1000); | ||
bfdev_log_notice("Total time: %lu.%lus\n", time / 1000, time % 1000); | ||
free(block); | ||
|
||
return 0; | ||
|