/*
 * http://charette.no-ip.com:81/programming/2013-08-05_Sleeping/
 * $Id: 2013-08-05_Sleeping.cpp 599 2014-08-30 07:31:10Z stephane $
 *
 * Example code to do some C++11 thread sleep testing.
 *
 * Compiled with the following:
 *
 *		g++ -O3 -std=c++11 2013-08-05_Sleeping.cpp && ./a.out
 */


#include <chrono>
#include <thread>
#include <iostream>


int main( int argc, char *argv[] )
{
    std::cout << "time elapsed (in nanoseconds):" << std::endl;

    for ( size_t idx = 0; idx < 5000; idx += 2 )
    {
        std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
        //std::this_thread::yield();
        //std::this_thread::sleep_for( std::chrono::nanoseconds(1) );
        //std::this_thread::sleep_for( std::chrono::nanoseconds(-1) );
        std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now();
        std::chrono::nanoseconds duration = end - start;
        std::cout << duration.count() << " ";
    }
    std::cout << std::endl;

    return 0;
}

