程序计数器(计算运行该程序所需的时间)

//计算运行该程序所需的时间


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

#define CLOCKS_PER_SEC ((clock_t)1000)//表示精度到毫秒

 //很明显,clock_t是一个长整形数。在time.h文件中,还定义了一个常量CLOCKS_PER_SEC,
   //它用来表示一秒钟会有多少个时钟计时单元(精度可以自己定义,但是注意,在标准C/C++中,最小的计时单位是一毫秒)


void timestart()
{
 long i = 0;
    clock_t start = 0;
 
    start = clock();//   clock()是C/C++中的计时函数,而与其相关的数据类型是clock_t
 
}


void timeend()
{
 double t = 0.00;
 clock_t start = 0;
 clock_t  end = 0;
 end = clock();
    //把结果转化成double型
    t = (double)(end - start) / CLOCKS_PER_SEC;

 
    printf("%lf seconds is used\n", t);
 
}


int main (void)
{
 
 int i;
 timestart();//在程序开始时开始计时

    for(i = 1; i <= 10000; i++)
  printf("%5d",2);

 timeend();//程序运行完结束计时
    return 0;
 
 
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值