c语言中如何计时, 在线求教

来源:百度知道 编辑:UC知道 时间:2024/06/15 10:54:39
我在C环境下 采集板卡数据 想知道30毫秒内能 采多少个数,请问这个时间如何确定 30毫秒用什么 函数来判断 谢谢

在开始时用time()函数取一次时间,在结束时(输入与生成相同时)再用time()取一次时间,之后求出再次时间之差即可。

*************************************************

#include <stdio.h> //for printf()
#include <stdlib.h> //for system()
#include <time.h> //for time() & time_t
void main()
{
time_t ts,te;
system("pause");
ts=time(NULL);
system("pause");
te=time(NULL);
printf("%ld\n",te-ts);

system("pause");

}
/////////////////////////////////////////////

输出两次按键之间的时间(秒)

给你写了一个模板 套进去就行了
#include “stdio.h”
#include “stdlib.h”
#include “time.h”

int main( void )
{
long i = 10000000L;
clock_t start, finish;
double duration;
/* 测量一个事件持续的时间*/
printf( "Time to do %ld empty loops is ", i );
start = clock();
while( i-- ); //把你的程序核心部分放到这里就行了