小编Ult*_*ntx的帖子

C语言中CLOCKS_PER_SEC找到time.h库

CLOCKS_PER_SEC 是否因系统而异,或者它对于操作系统是恒定的还是依赖于该特定系统的处理器?并且还帮我解释我的代码的输出......是吗??

#include<stdio.h>
#include<time.h>
int main()
{
int a;
long int b;
clock_t start, end;

start = clock();

//Code for which the time is to be calculated
for(a=0;;a++)
{
    if(a<0)
    {
        break;
    }
}
printf("int : %u\n",a);
for(b=0;;b++)
{
    if(b<0)
    {
        break;
    }
}
printf("long int :%u\n",b);
//code is over

end = clock();

//CLOCKS_PER_SECOND : the number of clock ticks per second
printf("Starting Time:%u\n",start);
printf("Ending Time:%u\n",end);
printf("CLOCKS_PER_SEC:%u",CLOCKS_PER_SEC);
printf("\nNumber of clock ticks:%u",(end - start));
printf("\nTotal time:%u",(double)(end - start)/CLOCKS_PER_SEC);
return 0;
} …
Run Code Online (Sandbox Code Playgroud)

c clock

2
推荐指数
1
解决办法
4765
查看次数

标签 统计

c ×1

clock ×1