最简单的
#include <time.h>
#include <stdio.h>
#include <dos.h>
int main(void)
{
time_t first, second;
first = time( NULL );
delay( 2000 );
second = time( NULL );
printf( "The difference is: %f seconds\n ",difftime(second,first));
return 0;
#include <time.h>
#include <stdio.h>
#include <dos.h>
int main(void)
{
time_t first, second;
first = time( NULL );
delay( 2000 );
second = time( NULL );
printf( "The difference is: %f seconds\n ",difftime(second,first));
return 0;
}秒
#include <time.h>
void f() {
time_t start,end,time;
start=clock();
//程序开始
//程序结束
end=clock();
time=end-start;//这里的时间是计算机内部时间
} 微秒
#include <time.h>
// At the beginning of your algorithm...
clock_t t1 = clock();
...
// At the end of your algorithm...
clock_t t2 = clock();
float seconds = (float)(t2-t1)/CLOCKS_PER_SEC;