C语言:
#include <time.h>
int main(void)
{
clock_t start, finish;
double duration;
start = clock();
/**待测程序段*/
finish = clock();
duration = (double)(finish - start)/ CLOCKS_PER_SEC;
printf("%f",duration);
return 0;
}
int main(void)
{
clock_t start, finish;
double duration;
start = clock();
/**待测程序段*/
finish = clock();
duration = (double)(finish - start)/ CLOCKS_PER_SEC;
printf("%f",duration);
return 0;
}
Java语言:
采用系统函数得到当前系统时间(以毫秒为单位):
long start = System.currentTimeMillis();
/**待测程序段*/
long end = System.currentTimeMillis();
System.out.println("Time: " + (end - start));
/**待测程序段*/
long end = System.currentTimeMillis();
System.out.println("Time: " + (end - start));