#include <stdio.h>
#include <time.h>
#include <math.h>

clock_t start, stop;    //clock_t为clock()返回的变量类型
double duration;        //记录被测函数运行时间,以秒为单位

int main(int argc, char **argv)
{
    /* 不再测试范围内的准备工作写在clock()调用之前 */

    //开始计时
    start = clock();
    //被测量的函数

    //停止计时
    stop = clock();
    //计算运行时间
    duration = ((double)(stop - start)) / CLOCKS_PER_SEC;

    /* 其他不在测试范围的处理写在后面, 例如输出duration的值 */
    printf("Running time: %6.2es.\n", duration);
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2021-08-24
  • 2022-01-07
  • 2021-07-29
  • 2021-12-28
  • 2021-07-04
  • 2022-02-07
  • 2022-12-23
猜你喜欢
  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案