mirror of
https://bitbucket.org/Mattrixwv/myhelpers.git
synced 2026-02-04 03:32:31 -05:00
Added a stopwatch to help time programs
This commit is contained in:
42
testStopwatch.c
Normal file
42
testStopwatch.c
Normal file
@@ -0,0 +1,42 @@
|
||||
//Programs/C/myHelpers/testStopwatch.c
|
||||
//Matthew Ellison
|
||||
// Created: 03-08-19
|
||||
//Modified: 03-08-19
|
||||
//This program is a simple test for the stopwatch struct and accompanying functions
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include "Stopwatch.h"
|
||||
|
||||
const int NUM_OF_RUNS = 10000;
|
||||
|
||||
|
||||
int main(){
|
||||
struct Stopwatch timer;
|
||||
init(&timer);
|
||||
start(&timer);
|
||||
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));
|
||||
|
||||
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
|
||||
*/
|
||||
Reference in New Issue
Block a user