[C] 如何用C实践Timer

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

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

 

#include <time.h> #include <stdio.h> #include <stdlib.h> 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,timer,System,input,Borland)