clock时钟周期
#include <iostream>
#include <ctime>int main() {clock_t start = clock(); // 获取开始时间的时钟周期数// 模拟一些工作for (long long i = 0; i < 10000000000; ++i);clock_t end = clock(); // 获取结束时间的时钟周期数std::cout << "start: " << static_cast<double>(start) / CLOCKS_PER_SEC << " seconds" << std::endl;std::cout << "end: " << static_cast<double>(end) / CLOCKS_PER_SEC << " seconds" << std::endl;// 计算所用时间(秒)double elapsed_time = static_cast<double>(end - start) / CLOCKS_PER_SEC;std::cout << "Elapsed time: " << elapsed_time << " seconds" << std::endl;return 0;
}
/*
start: 0.51 seconds
end: 3.087 seconds
Elapsed time: 2.577 seconds
*/