1
senghoo 2021 年 2 月 26 日 |
7
across 2021 年 2 月 26 日 @ly90907
#define T(f,...) do { \ time_t start = clock(); \ f(__VA_ARGS__); \ cout << #f << " running time is " <<float(clock()-start)/CLOCKS_PER_SEC<<" s"<<endl; \ }while (0) T(function_a,10); |
10
ly90907 OP 最终以如下方式实现
#define PRINT_FUNCTION_TIME(f) do { \ time_t start = clock(); \ f; \ std::string output = #f; \ cout << output.substr(0, output.find_first_of("(")) + " time = " <<float(clock()-start)/CLOCKS_PER_SEC<<" s"<<endl; \ }while (0) PRINT_FUNCTION_TIME(test()); PRINT_FUNCTION_TIME(test2(a,b,c)); |
11
byaiu 2021 年 2 月 26 日 via iPhone
这不是很多库都有的东西么……现在大众 cpp 的水平都这样了?
|