用C写的计算运行时间

#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", duration ); 
   system("pause"); 
} 

  

posted @ 2016-04-21 17:54  一双拖鞋走天下  阅读(180)  评论(0编辑  收藏  举报