ctime
clock()是一个无参函数,返回值是一个以毫秒为单位的整形
#include <ctime>
#include <iostream>
long t1 = clock();
****
Doing something
****
long t2 = clock();;
std::cout << t2 - t1 << "ms\n";
chrono
#include <chrono>
#include <iostream>
std::chrono::time_point<std::chrono::steady_clock> t1 = std::chrono::steady_clock::now();
****
Doing something
****
std::chrono::time_point<std::chrono::steady_clock> t2 = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsed1 = t2 - t1;
std::cout << "t2 - t1: " << elapsed1.count() << "s\n" << std::endl;
std::cout << "t2 - t1: " << std::chrono::duration_cast<std::chrono::milliseconds>(elapsed1).count() << "ms\n"<< std::endl;
参考链接
https://www.cnblogs.com/jwk000/p/3560086.html
https://en.cppreference.com/w/cpp/chrono
https://en.cppreference.com/w/cpp/chrono/duration