std::chrono::file_clock::now
提供: cppreference.com
< cpp | chrono | file clock
staticstd::chrono::time_point<std::chrono::file_clock> now()noexcept; | (C++11以上) | |
時の現在点を表す time point を返します。
[編集]引数
(なし)
[編集]戻り値
現在時刻を表す time point。
[編集]例
Run this code
#include <iostream>#include <vector>#include <numeric>#include <chrono> volatileint sink;int main(){for(auto size = 1ull; size < 1000000000ull; size *=100){// record start timeauto start = std::chrono::file_clock::now();// do some workstd::vector<int> v(size, 42); sink =std::accumulate(v.begin(), v.end(), 0u);// make sure it's a side effect// record end timeauto end = std::chrono::file_clock::now();std::chrono::duration<double> diff = end-start;std::cout<<"Time to fill and iterate a vector of "<< size <<" ints : "<< diff.count()<<" s\n";}}
出力例:
Time to fill and iterate a vector of 1 ints : 2.43e-07 s Time to fill and iterate a vector of 100 ints : 4.1e-07 s Time to fill and iterate a vector of 10000 ints : 2.519e-05 s Time to fill and iterate a vector of 1000000 ints : 0.00207669 s Time to fill and iterate a vector of 100000000 ints : 0.423087 s