问题描述
我刚开始使用C ++,有时我不知道我的编译器会喜欢两种不同的算法实现方式.我可以使用一个简单工具来查看我的代码执行多少时间吗?
I'm at the beginning with C++ and sometimes I don't know how much my compiler will like two different implementation of an alghoritm.Is there a simple tool I can use to see how much time takes my code to execute?
我正在使用gcc编译器
Im using gcc compiler
推荐答案
如果您想确定整个程序运行了多长时间,则应使用Code-Blocks/Visual Studio告诉您程序何时关闭.它应该在底部的日志中.
If you want to mesure how long the entire program run's, then Code-Blocks/Visual studio shouldtell you when the program closes. It should be in the log at the bottom.
如果您想确定一条特定的线或功能需要花费多长时间,我建议您进行研究 clock()
或 QueryPerformanceFrequency()
以及如何使用它们.
If you want to mesure how long a specific line, or function takes, I would suggjest researchingclock()
or QueryPerformanceFrequency()
and how to use them.
clock()
函数很慢,但使用起来更容易.一个例子:
the clock()
function is slow, but it's easyer to use. an example:
float start_time = clock()/CLOCKS_PER_SEC;
func();
float end_time = clock()/CLOCKS_PER_SEC;
float dtime = start_time - end_time;
这篇关于Windows上的C ++ Profiler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!