std::chrono::steady_clock::now
STD::时间::稳定[医]时钟::现在
static std::chrono::time_point | | (since C++11) |
---|
返回表示当前时间点的时间点。
参数
%280%29
返回值
表示当前时间的时间点。
例外
noexcept
规格:
noexcept
例
二次
#include <iostream>
#include <vector>
#include <numeric>
#include <chrono>
volatile int sink;
int main()
{
for (auto size = 1ull; size < 1000000000ull; size *= 100) {
// record start time
auto start = std::chrono::steady_clock::now(
// do some work
std::vector<int> v(size, 42
sink = std::accumulate(v.begin(), v.end(), 0u // make sure it's a side effect
// record end time
auto end = std::chrono::steady_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
二次
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。