JiXieShi 2024-06-20 21:58:30 +08:00
parent 6ddfc4b320
commit 60e82d529a
4 changed files with 44 additions and 38 deletions

View File

@ -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
////////////////////////

View File

@ -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

View File

@ -2,6 +2,7 @@
// Created by lydxh on 2024/5/9.
//
#include <stdio.h>
#include <ctime>
#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);
}

41
main.c
View File

@ -8,39 +8,6 @@
#include "tool.h"
#include <time.h>
/**
* @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;
}