69,371
社区成员
发帖
与我相关
我的任务
分享
printf( "%lf seconds\n", duration );
Time to do 10000000 empty loops is 0.025000 seconds
#include <stdio.h>
#include <conio.h>
#include <time.h>
void sleep( clock_t wait );
void main( void )
{
long i = 1000000000L;
clock_t start, finish;
double duration;
printf( "Delay for two seconds\n" );
sleep(2000);
printf( "Done!\n" );
printf( "Time to do %ld empty loops is ", i );
start = clock();
while( i-- ) ;
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf( "%lf seconds\nOver!\n", duration );
getch();
}
void sleep( clock_t wait )
{
clock_t goal;
goal = wait + clock();
while( goal > clock() ) ;
}
///////////////////////////////////////////////////////////////////
Delay for two seconds
Done!
Time to do 1000000000 empty loops is 2.510000 seconds
Over!
Delay for two seconds
Done!
Time to do 1000000000 empty loops is 2.505000 seconds
Over!
Delay for two seconds
Done!
Time to do 1000000000 empty loops is 2.485000 seconds
Over!
#incldue <time.h>
time_t begin = time();
// operating
time_t end = time();
end - begin//