编译后,如何使其显示计算时间?
c++ visual studio10 After compiling, how do i make it so that it displays the calculation time
我不知道你怎么称呼它…使用visualstudio10编译后,会弹出黑屏显示结果。
我注意到在youtube视频上,在他们的屏幕上,它也显示了计算所需的时间。(未编译时间)
我很确定答案就在那里,但我不知道搜索的关键字
这是一个我用来计时的小秒表类。准确性是……嗯…你做得越多越好,就这么说吧。
#include <sstream>
#include <chrono>
class Stopwatch final
{
public:
Stopwatch()
{
Reset();
}
void Reset()
{
MyCurrentTime = MyClock.now();
}
double Elapsed() const
{
auto elapsed = std::chrono::duration_cast<std::chrono::duration<double>>(MyClock.now() - MyCurrentTime);
return elapsed.count();
}
int ms() const
{
return static_cast<int>(0.5 + Elapsed() * 1000);
}
std::string ToMilliseconds() const
{
auto o = std::ostringstream();
o << ms();
return o.str();
}
std::string ToSeconds(int precision) const
{
auto o = std::ostringstream();
o.precision(precision);
o << std::fixed << Elapsed();
return o.str();
}
private:
std::chrono::high_resolution_clock MyClock;
std::chrono::high_resolution_clock::time_point MyCurrentTime;
};
一个小例子:
omp_get_wtime
#include <omp.h>
int main(void)
{
double dStart = omp_get_wtime();
Calculations();
double dEnd = omp_get_wtime();
std::cout << "Calculation took: " << dEnd - dStart << " sec." std::endl;
return 0;
}
相关文章:
- 如何计算Big-O表示法中的平均渐近运行时间
- 通过字符串来计算长度需要更长的时间,而不是移动字符串几次?
- 如何计算此排序函数的时间复杂度?
- 计算两个代码块的时间复杂度
- 如何使用发送数据包所花费的时间计算两个节点之间的距离?
- 如何计算函数的时间复杂度?
- 标准::映射::合并的计算时间复杂度
- 以小于一毫秒的精度计算时间的功能
- 更好地线程化代码以减少计算时间的方法
- 像儒略数字用于计算日期一样,是否有任何特定的数字来计算时间
- C++ctime.h将无法正确计算时间
- c++/Qt—计算时间
- 计算时间增量最快的linux C时间函数是什么?看到clock_gettime和gettimeofday表现不佳
- c++ Boost:以毫秒计算时间
- 使用chrono c++库计算时间戳的差异
- 编译后,如何使其显示计算时间?
- 如何在c++中计算时间
- 使用mktime计算时间不正确,以获得UTC+8
- 用c++计算时间
- Boost多边形库布尔函数计算时间