Created
October 23, 2019 01:09
-
-
Save zhangxiaomu01/4a46dfa239d06b549dc8ce31b9c9abd8 to your computer and use it in GitHub Desktop.
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
int main(){ | |
std::ratio<1, 10> r; //1/10 | |
cout << r.num << "/" << r.den <<endl; | |
//ALl clock frequency is represented by a ratio, we can print the | |
//ratio using the similar approach. | |
cout << chrono::system_clock::period::num <<"/" <<chrono::steady_clock::period::den <<endl; | |
//duration: | |
chrono::microseconds mi(2700);//2700 microseconds! | |
mi.count(); //get the value 2700 here | |
//2700000 nanoseconds. The coverssion works fine here for we are converting | |
//low resolution to high resolution | |
chrono::nanoseconds na = mi; | |
na.count(); //get the value 2700000 here | |
//We need to do the cast here if we want to convert high resolution | |
//to low resolution. 2 milliseconds, the value is truncated. | |
chrono::milliseconds mill = chrono::duration_cast<chrono::milliseconds>(mi); | |
mi = mill + mi; //4700 | |
//Time point// | |
//current time of system clock | |
chrono::system_clock::time_point tp = chrono::system_clock::now(); | |
cout << tp.time_since_epoch().count() << endl; | |
tp = tp + chrono::seconds(2); | |
cout << tp.time_since_epoch().count() << endl; | |
//Measure the time span | |
chrono::steady_clock::time_point start = chrono::steady_clock::now(); | |
cout <<"I am bored!!!" <<endl; | |
chrono::steady_clock::time_point end = chrono::steady_clock::now(); | |
chrono::steady_clock::duration d = end - start; | |
if(d == chrono::steady_clock::duration::zero()){ | |
cout << "No time elapsed!" <<endl; | |
} | |
cout << chrono::duration_cast<chrono::microseconds>(d).count() <<endl; | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment