如何衡量代码效率? [英] How to measure code-efficiency?
问题描述
时不时地找到两种解决问题的方法。我试着
找到一种方法来决定哪一个是最好的(至少在速度方面)但是我
我不知道如何测试它有多长拿一个程序来运行?
Every now and then and found two ways to resolve a problem. I try to
find a way to decide which one is best (at least speed-wise) but I
don''t know how do I test how long those it take a program to run?
推荐答案
Gaijinco写道:
Gaijinco wrote:
时不时地找到两种解决问题的方法。我试图找到一种方法来决定哪一个是最好的(至少在速度方面),但我不知道如何测试程序运行多长时间?
Every now and then and found two ways to resolve a problem. I try to
find a way to decide which one is best (at least speed-wise) but I
don''t know how do I test how long those it take a program to run?
我会给你一个普通的计时器(其中一个在
马拉松期间使用):用一只手开始,而你用另一个按
one。
祝你好运...
告诉它如何去
I would you a regular timer (one of those that are used during
marathons): start in one hand, while you press enter with a different
one.
Good luck...
tell how it went
Gaijinco写道:
Gaijinco wrote:
时不时地找到两种解决问题的方法。我试图找到一种方法来决定哪一个是最好的(至少在速度方面),但我不知道如何测试程序运行多长时间?
Every now and then and found two ways to resolve a problem. I try to
find a way to decide which one is best (at least speed-wise) but I
don''t know how do I test how long those it take a program to run?
我执行这样的时间代码:
#include< ctime>
// ...
clock_t t0 = clock();
//插入要定时的代码 - -
double tElapsedSec = clock() - t0;
tElapsedSec / = CLOCKS_PER_SEC;
// ...
DW
I time code execution like this:
#include <ctime>
// ...
clock_t t0 = clock();
// ---- insert code to be timed ----
double tElapsedSec = clock() - t0;
tElapsedSec /= CLOCKS_PER_SEC;
// ...
DW
> #include< ctime>
> #include <ctime>
// ...
clock_t t0 = clock();
// - - 插入要定时的代码----
double tElapsedSec = clock() - t0;
tElapsedSec / = CLOCKS_PER_SEC;
// ...
// ...
clock_t t0 = clock();
// ---- insert code to be timed ----
double tElapsedSec = clock() - t0;
tElapsedSec /= CLOCKS_PER_SEC;
// ...
但是,如果经过的时间非常低,则会显示0.是否有任何方式
来衡量千分之一秒?
However, if the time elapsed is really low it shows 0. Is there any way
to measure thousandths of a second?
这篇关于如何衡量代码效率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!