现在的位置: 首页 > 综合 > 正文

测试一条代码运行的时间

2012年03月08日 ⁄ 综合 ⁄ 共 265字 ⁄ 字号 评论关闭

CODE:

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

int main()
{
    int time;
    printf("Input how much times that you wanna run this progrma?\n\ntime = ");
    scanf("%d", &time);
    int i = 0;
    long start, end;

    start = clock();
    while (time--) ++i;
    end = clock();

    printf("time = %ld (ms)\n", end - start);
    return 0;
}

 

抱歉!评论已关闭.