Updated to give better names

This commit is contained in:
2019-03-11 11:54:33 -04:00
parent 6c36ade440
commit 4367c34874
2 changed files with 63 additions and 48 deletions

View File

@@ -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
*/