mirror of
https://bitbucket.org/Mattrixwv/myhelpers.git
synced 2026-02-04 03:32:31 -05:00
Updated to give better names
This commit is contained in:
@@ -29,30 +29,45 @@ const int NUM_OF_RUNS = 10000;
|
||||
|
||||
|
||||
int main(){
|
||||
struct Stopwatch timer;
|
||||
init(&timer);
|
||||
start(&timer);
|
||||
struct Stopwatch timer; //Create the stopwatch
|
||||
initStopwatch(&timer); //Initialize the stopwatch
|
||||
|
||||
//Start the stopwatch counting
|
||||
startStopwatch(&timer);
|
||||
|
||||
//Perform some calculation
|
||||
for(int cnt = 0;cnt < NUM_OF_RUNS;++cnt){
|
||||
printf("%d\n", cnt);
|
||||
}
|
||||
stop(&timer);
|
||||
printf("It took %d nanoseconds to run this program\n", getNano(&timer));
|
||||
printf("It took %f microseconds to run this program\n", getMicro(&timer));
|
||||
printf("It took %f milliseconds to run this program\n", getMilli(&timer));
|
||||
printf("It took %f seconds to run this program\n", getSecond(&timer));
|
||||
printf("It took %f minutes to run this program\n", getMinute(&timer));
|
||||
printf("It took %f hours to run this program\n", getHour(&timer));
|
||||
printf("It took %s to run this program\n", getStr(&timer));
|
||||
|
||||
//Stop the stopwatch counting
|
||||
stopStopwatch(&timer);
|
||||
|
||||
//Get a string about the time
|
||||
char* timerStr = getStrStopwatch(&timer);
|
||||
|
||||
//Print the results
|
||||
printf("It took %u nanoseconds to run this program\n", getNanoStopwatch(&timer));
|
||||
printf("It took %f microseconds to run this program\n", getMicroStopwatch(&timer));
|
||||
printf("It took %f milliseconds to run this program\n", getMilliStopwatch(&timer));
|
||||
printf("It took %f seconds to run this program\n", getSecondStopwatch(&timer));
|
||||
printf("It took %f minutes to run this program\n", getMinuteStopwatch(&timer));
|
||||
printf("It took %f hours to run this program\n", getHourStopwatch(&timer));
|
||||
printf("It took %s to run this program\n", timerStr);
|
||||
|
||||
//Free the memory used in the string
|
||||
free(timerStr);
|
||||
timerStr = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Results:
|
||||
It took 1289000000 nanoseconds to run this program
|
||||
It took 1289000.000000 microseconds to run this program
|
||||
It took 1289.000000 milliseconds to run this program
|
||||
It took 1.289000 seconds to run this program
|
||||
It took 0.021483 minutes to run this program
|
||||
It took 0.003581 hours to run this program
|
||||
It took 1.288 seconds to run this program
|
||||
It took 1938000000 nanoseconds to run this program
|
||||
It took 1938000.000000 microseconds to run this program
|
||||
It took 1938.000000 milliseconds to run this program
|
||||
It took 1.938000 seconds to run this program
|
||||
It took 0.032300 minutes to run this program
|
||||
It took 0.005383 hours to run this program
|
||||
It took 1.938 seconds to run this program
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user