main
parent
6ddfc4b320
commit
60e82d529a
|
@ -37,7 +37,7 @@
|
||||||
#define LOG_TIMER
|
#define LOG_TIMER
|
||||||
//#define LOG_FOR_MCU
|
//#define LOG_FOR_MCU
|
||||||
#define LOG_LINE_END_CRLF
|
#define LOG_LINE_END_CRLF
|
||||||
#define LOG_WITH_RUN_TIMER
|
//#define LOG_WITH_RUN_TIMER
|
||||||
#define LOG_OUTPUT_LVL LOG_LVL_INFO
|
#define LOG_OUTPUT_LVL LOG_LVL_INFO
|
||||||
////////////////////////
|
////////////////////////
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,27 @@ float Str2Float(char *str);
|
||||||
printf(fmt " ", arr[i]); }\
|
printf(fmt " ", arr[i]); }\
|
||||||
printf("\n"); } while (0)
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// Created by lydxh on 2024/5/9.
|
// Created by lydxh on 2024/5/9.
|
||||||
//
|
//
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <ctime>
|
||||||
#include "tool.h"
|
#include "tool.h"
|
||||||
|
|
||||||
float Mapping(float val, float I_Min, float I_Max, float O_Min, float O_Max) {
|
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;
|
decimal /= decimalWeight;
|
||||||
return float(sign * (integer + decimal));
|
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
41
main.c
|
@ -8,39 +8,6 @@
|
||||||
#include "tool.h"
|
#include "tool.h"
|
||||||
#include <time.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() {
|
int main() {
|
||||||
srand((unsigned) time(NULL));
|
srand((unsigned) time(NULL));
|
||||||
|
@ -50,9 +17,9 @@ int main() {
|
||||||
char str[] = "123.456";
|
char str[] = "123.456";
|
||||||
float result = Str2Float(str);
|
float result = Str2Float(str);
|
||||||
printf("Result: %.3f\n", result);
|
printf("Result: %.3f\n", result);
|
||||||
// Test("SPI", Test_spi);
|
Test_RunTime("SPI", Test_spi);
|
||||||
// Test("IIC", Test_iic);
|
// Test_RunTime("IIC", Test_iic);
|
||||||
// Test("ArgPase", Test_argpase);
|
// Test_RunTime("ArgPase", Test_argpase);
|
||||||
// Test("Task", Test_task);
|
// Test_RunTime("Task", Test_task);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue