VS中统计程序的运行时间

在windowns下,统计VS中代码的运行时间。

使用函数:clock_t clock(void) ;
简单而言,就是该程序从启动到函数调用占用CPU的时间。这个函数返回从“开启这个程序进程”到“程序中调用clock()函数”时之间的CPU时钟计时单元(clock tick)数,在MSDN中称之为挂钟时间(wal-clock);若挂钟时间不可取,则返回-1。其中clock_t是用来保存时间的数据类型。
 

代码测试:

#include “stdio.h” 
#include “stdlib.h” 

#include "time.h"//统计时间需添加的头文件

void main()
{
    clock_t start, finish;
    double duration;
    start = clock();

    xxxxxxx;//操作步骤

    finish = clock();
    duration = (double)(finish - start) / CLOCKS_PER_SEC;
    printf("%f seconds\n", duration);

}

猜你喜欢

转载自blog.csdn.net/u013925378/article/details/83025903