C++ 剖析C++;程序
我有一个功能的个人资料的时间。实际上,当检入主功能时,该功能显示的时间为C++ 剖析C++;程序,c++,profiling,C++,Profiling,我有一个功能的个人资料的时间。实际上,当检入主功能时,该功能显示的时间为13222668微秒(13秒)。然后我开始分析函数的不同部分,最简单的示例如下所示: #include <iostream> #include <sstream> #include <string> #include <chrono> using namespace std::chrono; unsigned int match_time; int func(){ uns
13222668
微秒(13秒)。然后我开始分析函数的不同部分,最简单的示例如下所示:
#include <iostream>
#include <sstream>
#include <string>
#include <chrono>
using namespace std::chrono;
unsigned int match_time;
int func(){
unsigned int i = 0;
while(i < 20){
high_resolution_clock::time_point t1 = high_resolution_clock::now(); // if I start the time from here, it shows me just `827687` milliseconds (827 milliseconds).
//code....
{
//code...
{
//code....
}
//code....
}
high_resolution_clock::time_point t2 = high_resolution_clock::now();
auto duration = duration_cast<microseconds>( t2 - t1 ).count();
match_time += duration;
i++;
}
return 0;
}
我得到了一个很高的时间13222668
微秒(13秒),我对此表示怀疑
另外,当我检查不同语句执行的时间时,我得到打印时的0
time(我认为这是一个打印问题)和总和match\u time+=duration其中代码>在数百万次运行期间显示(827毫秒)
我想知道我的时间分析方法是否正确,以及为什么时间在while循环和outside循环内变化(我怀疑是关于outside循环时间)。我的代码是否由于其他原因而挂起了一段时间。难道不是因为你的匹配时间没有初始化吗?是一个相关的问题。@basilestrynkevich谢谢,但我需要知道为什么时间会变化,我认为有一些问题会让我的代码保持一段时间,如果我使用while循环之外的时间,就会清楚地显示出来。执行时间是不可复制的(因为有很多缓存)@ BaselestalyKev痒,我理解,但是差别是如此巨大(12秒),那么我会认为 HyLyRealPosithCalths一种学术上的好奇心。
high_resolution_clock::time_point t1 = high_resolution_clock::now();
while(i < 20){
}
high_resolution_clock::time_point t2 = high_resolution_clock::now();
auto duration = duration_cast<microseconds>( t2 - t1 ).count();
match_time += duration;