feat(core): add a function profiling utilities
Description
Added a profiling macro that takes a function/lambda and execute it 'n' times. It computes the average execution time with the standard error. Optionally, it can continue to loop until a given error "ratio" ("standard error" / "mean") is reached, ensuring some level of accuracy.
Also:
- Added "/Zc:preprocessor" windows compile flag to support
__VA_OPT__
c++20 macro, which also triggers more warning, since the compiler / preprocessor is now stricter. For example,std::transform(string.begin(), string.end(), std::to_upper)
doesn't work anymore sincestd::to_upper()
returns anint
which is greater than the destination (char).. - Fix all warnings due to C4244
- restore PCH=off for windows (which can be useful to fix lint pass since clang-tidy use this configuration to be a bit faster)
Closes #988 (closed)
How to test it?
Call in a unit test, something like:
FW_PROFILE_FUNC(
[&]
(std::size_t i) /// i is the current iteration
{
/// some code to profile
my_code_to_call();
},
10, /// At least 10x
"A label to find it in the log",
0.1 /// the error ratio to reach (standard_error / mean)
);
Or look at the modified libs\io\bitmap\test\tu\WriterTest.cpp
Some results
Sample output:
[01.11.2022 11:15:12.126270][00:00:03.219552][0x00000494][0x00003714][info] [libs\io\bitmap\test\tu\WriterTest.cpp:413] NVJPEG (FAST) : average time (3 iterations) = 6.8092 ms, standard error = 0.422708 ms