[C] 如何用C实践Timer

这段代码示范如何用C实践Timer

这个范例用Borland C++ 3.1编译册试过...

 

#include #include #include double BeginTimer() { //timer declaration double Begin; //initialize Begin Begin = clock() / CLK_TCK; //start the timer return Begin; } double EndTimer(double begin) { double End; End = clock() / CLK_TCK; //stop the timer return End - begin; } int main () { char input; double passed; double begin = BeginTimer(); printf ("Timer set to: %.2f/n", begin); // print the initialised timer (0) // process to be timed goes here printf ("Enter something to stop the timer: "); scanf ("%c", &input); passed = EndTimer(begin); // stop the timer printf("Ticks passed: %.4f secound/n",passed); system("pause"); return 0; }

你可能感兴趣的:(C/C++)