Created
November 12, 2018 11:01
-
-
Save spockwangs/cf0d578708dd73409629740f5aea2afb to your computer and use it in GitHub Desktop.
test sleep precision
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2018 spockwang. | |
// All rights reserved. | |
// | |
// Author: wbbtiger@gmail.com | |
// | |
#include <chrono> | |
#include <iostream> | |
#include <thread> | |
using namespace std; | |
int main() | |
{ | |
int wait_micros = 100; | |
int cnt = 10*10000000 / wait_micros; | |
auto start_time = std::chrono::steady_clock::now(); | |
for (int i = 0; i < cnt; ++i) { | |
std::this_thread::sleep_for(std::chrono::microseconds(wait_micros)); | |
} | |
auto end_time = std::chrono::steady_clock::now(); | |
auto duration_micros = std::chrono::duration_cast<std::chrono::microseconds>(end_time-start_time).count(); | |
cout << "avg micros=" << (duration_micros/cnt) << endl; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment