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

I tried to find a way to measure the time code without using the restrictions below.

In my requirement, this is for an embedded system that has very strict matches.

All I could find was to use C headers, unapproved headers according to Google C ++ coding standards, or boost that were excluded from project conformance.

I looked at the proposed posts that looked similar, but could not find the answer to what I was looking for. Please, help!

Restrictions should not use the following,

This style check has a list down chrono as unapproved. https://github.com/google/styleguide/blob/gh-pages/cpplint/cpplint.py

+4
source share
4 answers

If we are talking about C ++ 11, the only way is to use std::chrono. The Google Style Guide is not some kind of final authority here (sometimes it is very doubtful).

std::chronoit is proven that it is good and stable and even used in gaming machines in AAA games, see for yourself HERE . A good example of what you need is HERE

, ++ 11, , , C, .

- API, <time.h>, .

+8

GPIO , . , GPIO . - . .

: . GPIO- .

+3

Is time measurement required in the final product? If not, I would suggest using whatever you like and using a switch so that you do not compile these measurement procedures into the final product.

+2
source

Something like this you mean? (for Windows platform)

#include <Windows.h>

class stopwatch
{
    double PCFreq = 0.0;
    double CounterStart = 0; //google style compliant, less accurate
    //__int64 CounterStart = 0; //for accuracy
    LARGE_INTEGER li;

public:

    void StartCounter()
    {
        if (!QueryPerformanceFrequency(&li))ExitProcess(0);
        PCFreq = double(li.QuadPart) / 1000.0;
        QueryPerformanceCounter(&li); CounterStart = li.QuadPart;
    }

    double GetCounter() { QueryPerformanceCounter(&li); return double(li.QuadPart - CounterStart) / PCFreq; }
};

using:

stopwatch aclock;
aclock.StartCounter(); //start
//....///
cout<<aclock.GetcCounter()<<endl; //output time passed in milliseconds
-1
source

Source: https://habr.com/ru/post/1661680/


All Articles