diff options
Diffstat (limited to 'SpMV/include/timer.h')
-rw-r--r-- | SpMV/include/timer.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/SpMV/include/timer.h b/SpMV/include/timer.h new file mode 100644 index 0000000..cb513cb --- /dev/null +++ b/SpMV/include/timer.h @@ -0,0 +1,54 @@ +#pragma once + +#include <stdio.h> +#include <sys/time.h> + +#if DFATOOL_TIMING + +#define dfatool_printf(fmt, ...) do { printf(fmt, __VA_ARGS__); } while (0) + +typedef struct Timer { + struct timeval startTime; + struct timeval endTime; +} Timer; + +static void startTimer(Timer *timer) +{ + gettimeofday(&(timer->startTime), NULL); +} + +static void stopTimer(Timer *timer) +{ + gettimeofday(&(timer->endTime), NULL); +} + +static double getElapsedTime(Timer timer) +{ + return ((double)((timer.endTime.tv_sec - timer.startTime.tv_sec) + + (timer.endTime.tv_usec - + timer.startTime.tv_usec) / 1.0e6)); +} + +#else + +#define dfatool_printf(fmt, ...) do {} while (0) + +typedef int Timer; + +static void startTimer(Timer* timer) +{ + (void)timer; +} + +static void stopTimer(Timer* timer) +{ + (void)timer; +} + +static double getElapsedTime(Timer timer) +{ + (void)timer; + return 0.0; +} + +#endif |