Skip to content

Instantly share code, notes, and snippets.

@nekko1119
Created January 27, 2015 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nekko1119/e30c24aa655026f9cd52 to your computer and use it in GitHub Desktop.
Save nekko1119/e30c24aa655026f9cd52 to your computer and use it in GitHub Desktop.
C++時間計測用コード
#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