方法一:单位为秒,调用 tim.h
void test2() { double dur; clock_t start,end; start = clock(); foo();//dosomething end = clock(); dur = (double)(end - start); printf("Use Time:%f\n",(dur/CLOCKS_PER_SEC)); }
方法二:单位为秒,调用 tim.h
time_t tstart, tend; tstart = time(0); tend = time(0); cout << "It took "<< difftime(tend, tstart)*1000 <<" second(ms)."<< endl;
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/207641.html原文链接:https://javaforall.net
