C语言实现毫秒级定时

来源:互联网 发布:java在物联网中的应用 编辑:程序博客网 时间:2024/06/02 00:26

#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-- )
    finish = clock();
    duration = (double)(finish - start) / CLOCKS_PER_SEC;
    printf( "%f seconds/n", duration );
    system("pause");
}


程序执行结果:

Time to do 10000000 empty loops is 0.421000 seconds
请按任意键继续...

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wave_1102/archive/2008/04/29/2343479.aspx

原创粉丝点击