Created
January 27, 2015 17:05
-
-
Save nekko1119/e30c24aa655026f9cd52 to your computer and use it in GitHub Desktop.
C++時間計測用コード
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
#include <chrono> | |
#include <utility> | |
template <class F, class ...Args> | |
std::chrono::system_clock::duration take_time(F&& f, Args&&... args) { | |
namespace chrono = std::chrono; | |
auto const begin = chrono::system_clock::now(); | |
f(std::forward<Args>(args)...); | |
auto const end = chrono::system_clock::now(); | |
return end - begin; | |
} | |
#include <iostream> | |
#include <thread> | |
int main() { | |
auto const time = take_time([] (int millis){ | |
std::chrono::milliseconds n(millis); | |
std::this_thread::sleep_for(n); | |
}, 5); | |
std::cout << "time: " << std::chrono::duration_cast<std::chrono::milliseconds>(time).count() << " ms" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment