Last active
January 20, 2018 06:25
-
-
Save HongfeiXu/9574873fa40f683ca40316f4b223f44d to your computer and use it in GitHub Desktop.
使用 C++11 中的 chrono 库 测量时间
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
/* | |
时间测量 | |
使用 C++11 中的 chrono 库 | |
http://en.cppreference.com/w/cpp/chrono/duration/duration_cast | |
*/ | |
#include <chrono> | |
#include <iostream> | |
#include <vector> | |
int main() | |
{ | |
std::vector<int> v; | |
auto t0 = std::chrono::high_resolution_clock::now(); | |
for (int i = 0; i < 10000; ++i) | |
v.push_back(i); | |
auto t1 = std::chrono::high_resolution_clock::now(); | |
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0).count() << "ms\n"; | |
return 0; | |
} | |
/* | |
6ms | |
请按任意键继续. . . | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment