This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler: <chrono> support

Expert 1635 points

Tool/software: TI C/C++ Compiler

As I continue my exploration of the brand-new compiler supporting c++14 I would like to ask if <chrono> is supported.

I was able to successfully compile a simple app that tries to measure the running time of a loop. Still, it seems there is no timer linked to either chrono::system_clock, or chrono::steady_clock, or chrono::high_resolution_clock, nor any obvious way to configure it. As a consequence, casting the values obtained at two different points with now() gives always 0 (no matter the resolution used).

Thanks,

Pibe

  • As long as your OS provides proper time() and clock() functions, it is expected that the <chrono> support will work. Are you running this test case in a hosted environment (under the debugger)? If not, are you using SYS/BIOS? Does your application provide its own time() or clock() function? What ISA are you using? Can you provide a test case demonstrating what doesn't work?
  • This was a simple test on bare metal:

    #include <chrono>
    #include <iostream>
    
    using namespace std;
    
    int main( void )
    {
        auto test_start = chrono::steady_clock::now();
    
        // **** "Test" ****
        for( int i = 5 ; i > 0 ; i-- )
            cout << "Now!" << endl;
        // ****************
    
        auto duration = chrono::steady_clock::now() - test_start;
        auto nanosecs = chrono::duration_cast<chrono::nanoseconds>(duration);
    
        cout << "Test ran for " << nanosecs.count() << " nanosecs" << endl;
    }
    

    I think it would not be a bad idea to provide backend support for <chrono> on bare metal. Something like having an option in the project configuration to configure a user selected timer. Just a thought.

  • It is very likely the <chrono> familiy of functions will, on an embedded system, have all the same issues discussed in the article Time and clock RTS Functions.  Those low level details, which require close coordination with HW we do not specify or control, are left to the user.

    Thanks and regards,

    -George