Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best C++11 way to measure code execution time for an Embedded system

Tags:

c++

c++11

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,

  • Boost libraries
  • 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

like image 232
SajithP Avatar asked Dec 11 '22 14:12

SajithP


2 Answers

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.

like image 67
Starl1ght Avatar answered Feb 16 '23 00:02

Starl1ght


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.

like image 35
Alexey Guseynov Avatar answered Feb 15 '23 23:02

Alexey Guseynov