使用方法:
template <typename T>
void meansure(T&& func){
//应用用来计时的命名空间,该命名空间包含在std中
using namespace std::Chrono;
//开始计时
auto start = system_clock::now();
duration<double> diff = system_clock::now() - start;
func();
cout<<"elapsed :"<< dif.count<<" s"<<endl;
}
本文介绍了一种使用C++标准库中的chrono模块来测量函数运行时间的方法。通过定义一个通用模板函数,可以方便地应用于各种类型的数据和函数上,为性能测试和优化提供了便利。
682

被折叠的 条评论
为什么被折叠?



