Skip to content

Instantly share code, notes, and snippets.

@helloobaby
Last active October 20, 2022 12:12
Show Gist options
  • Select an option

  • Save helloobaby/096d2bee53124f2b20c5e8f865f8b2c4 to your computer and use it in GitHub Desktop.

Select an option

Save helloobaby/096d2bee53124f2b20c5e8f865f8b2c4 to your computer and use it in GitHub Desktop.
c++ chrono库的使用
#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