diff --git a/lib/inc/log.h b/lib/inc/log.h index d3327df..4b1d28a 100644 --- a/lib/inc/log.h +++ b/lib/inc/log.h @@ -37,7 +37,7 @@ #define LOG_TIMER //#define LOG_FOR_MCU #define LOG_LINE_END_CRLF -#define LOG_WITH_RUN_TIMER +//#define LOG_WITH_RUN_TIMER #define LOG_OUTPUT_LVL LOG_LVL_INFO //////////////////////// diff --git a/lib/inc/tool.h b/lib/inc/tool.h index e177c77..ca0ba68 100644 --- a/lib/inc/tool.h +++ b/lib/inc/tool.h @@ -135,6 +135,27 @@ float Str2Float(char *str); printf(fmt " ", arr[i]); }\ printf("\n"); } while (0) +/** + * @brief 测试函数执行时间 + * @param name: [输入] 测试名称 + * @param pFunction: [输入] 指向待测试函数的指针 + * @return void + * @example Test("FunctionName", functionName); +**/ +void Test_RunTime(char *name, void (*pFunction)()); + +#define END "\n" +#define TYPE_F(v) _Generic((v), \ +char :"[char]-> "#v"=%c" END, \ +short :"[short]-> "#v"=%d" END, \ +int :"[int]-> "#v"=%d" END, \ +float :"[float]-> "#v"=%.2f" END , \ +double :"[double]-> "#v"=%.2f" END, \ +default: "[err]-> "#v"=%p" END) +#define POUT(s) printf(TYPE_F(s) ,s) + + + #ifdef __cplusplus } #endif diff --git a/lib/src/tool.cpp b/lib/src/tool.cpp index 8aaca93..00bf494 100644 --- a/lib/src/tool.cpp +++ b/lib/src/tool.cpp @@ -2,6 +2,7 @@ // Created by lydxh on 2024/5/9. // #include +#include #include "tool.h" float Mapping(float val, float I_Min, float I_Max, float O_Min, float O_Max) { @@ -71,3 +72,20 @@ float Str2Float(char *str) { decimal /= decimalWeight; return float(sign * (integer + decimal)); } + +void Test_RunTime(char *name, void (*pFunction)()) { + clock_t start, end; + double cpu_time_used; + + printf("\n------< %s TEST >------\n", name); + + start = clock(); + pFunction(); + end = clock(); + + cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; + + printf("\nTime taken by %s: %f seconds\n", name, cpu_time_used); + + printf("\n------< %s END >------\n", name); +} \ No newline at end of file diff --git a/main.c b/main.c index 8790172..748ceb2 100644 --- a/main.c +++ b/main.c @@ -8,39 +8,6 @@ #include "tool.h" #include -/** - * @brief 测试函数执行时间 - * @param name: [输入] 测试名称 - * @param pFunction: [输入] 指向待测试函数的指针 - * @return void - * @example Test("FunctionName", functionName); -**/ -void Test(char *name, void (*pFunction)()) { - clock_t start, end; - double cpu_time_used; - - printf("\n------< %s TEST >------\n", name); - - start = clock(); - pFunction(); - end = clock(); - - cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; - - printf("\nTime taken by %s: %f seconds\n", name, cpu_time_used); - - printf("\n------< %s END >------\n", name); -} - -#define END "\n" -#define TYPE_F(v) _Generic((v), \ -char :"[char]-> "#v"=%c" END, \ -short :"[short]-> "#v"=%d" END, \ -int :"[int]-> "#v"=%d" END, \ -float :"[float]-> "#v"=%.2f" END , \ -double :"[double]-> "#v"=%.2f" END, \ -default: "[err]-> "#v"=%p" END) -#define POUT(s) printf(TYPE_F(s) ,s) int main() { srand((unsigned) time(NULL)); @@ -50,9 +17,9 @@ int main() { char str[] = "123.456"; float result = Str2Float(str); printf("Result: %.3f\n", result); -// Test("SPI", Test_spi); -// Test("IIC", Test_iic); -// Test("ArgPase", Test_argpase); -// Test("Task", Test_task); + Test_RunTime("SPI", Test_spi); +// Test_RunTime("IIC", Test_iic); +// Test_RunTime("ArgPase", Test_argpase); +// Test_RunTime("Task", Test_task); return 0; }