Last active
October 20, 2022 12:12
-
-
Save helloobaby/096d2bee53124f2b20c5e8f865f8b2c4 to your computer and use it in GitHub Desktop.
c++ chrono库的使用
This file contains hidden or 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
| #define _CRT_SECURE_NO_WARNINGS | |
| #include <iostream> | |
| #include <chrono> | |
| #include <windows.h> | |
| using namespace std; | |
| int main(int ac, char* av[]) { | |
| auto start = chrono::steady_clock::now(); | |
| for (int i = 0; i < 100;i++) { | |
| string s("1234567"); | |
| } | |
| auto end = chrono::steady_clock::now(); | |
| chrono::duration<double> spend = end - start; | |
| // 计算间隔时间 | |
| cout << spend.count() << endl; | |
| // 输出当前时间 | |
| auto time = chrono::system_clock::to_time_t(chrono::system_clock::now()); | |
| cout << ctime(&time) << endl; | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment