I was trying to find a way to measure code execution time without using the below listed constraints.
In my requirement it's for an embedded system which has very strict conformances.
All I could found was using C headers, unapproved headers by Google C++ coding standards or boost which are excluded from the project conformances.
I looked through the suggested posts which looked similar but couldn't find an answer for what is looked for. Please help!
Constraints are not to use the following,
C system headers like sys/time.h
Unapproved headers like chrono
by Google C++ style guide https://google.github.io/styleguide/cppguide.html
Target platform is Linux
This style checker has list down chrono as unapproved.. https://github.com/google/styleguide/blob/gh-pages/cpplint/cpplint.py
If we are talking about C++11 - the only way is to use std::chrono
. Google style guide is not an some kind of final authority here (sometimes it is highly questionable).
std::chrono
is proven to be good and stable, and even used in game engines in AAA games, see for yourself HERE. Good example for exactly what you need is available HERE
In case if you still don't want it, there are no other C++11 way to do it, but you, probably, want to look on C-style measure, like HERE.
Just for your information - all methods are using system API, and so, <time.h>
is included, no way to avoid it.
For embedded systems there is a common practice to change GPIO state in your code and then hook an oscilloscope to the pin and look for resulting waveform. This has minimal impact on runtime because changing GPIO is a cheap operation. It does not require any libraries and additional code. But it requires additional hardware.
Note: embedded is quite stretchable notion. GPIO trick is more related for microcontrollers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With