diff --git a/include/timer.h b/include/timer.h index 35a5d6254..e46a40feb 100644 --- a/include/timer.h +++ b/include/timer.h @@ -6,16 +6,7 @@ #ifndef _TIMER_H #define _TIMER_H -#if defined (_WIN) - -#define hc_timer_get(a,r) { hc_timer_t hr_freq; QueryPerformanceFrequency (&hr_freq); hc_timer_t hr_tmp; hc_timer_set (&hr_tmp); (r) = (double) ((double) (hr_tmp.QuadPart - (a).QuadPart) / (double) (hr_freq.QuadPart / 1000)); } -#define hc_timer_set(a) { QueryPerformanceCounter ((a)); } - -#elif defined (_POSIX) - -#define hc_timer_get(a,r) { hc_timer_t hr_tmp; hc_timer_set (&hr_tmp); (r) = (double) (((hr_tmp.tv_sec - (a).tv_sec) * 1000) + ((double) (hr_tmp.tv_usec - (a).tv_usec) / 1000)); } -#define hc_timer_set(a) { gettimeofday ((a), NULL); } - -#endif +void hc_timer_set (hc_timer_t *a); +double hc_timer_get (hc_timer_t a); #endif // _TIMER_H diff --git a/src/monitor.c b/src/monitor.c index 53a3d6c79..b4574739e 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -291,9 +291,7 @@ static void monitor (hashcat_ctx_t *hashcat_ctx) if (status_ctx->devices_status == STATUS_PAUSED) { - double ms_paused_tmp = 0; - - hc_timer_get (status_ctx->timer_paused, ms_paused_tmp); + double ms_paused_tmp = hc_timer_get (status_ctx->timer_paused); ms_paused += ms_paused_tmp; } diff --git a/src/opencl.c b/src/opencl.c index d26668164..d5a53c993 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -380,9 +380,7 @@ int choose_kernel (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, co const u64 perf_sum_all = (u64) (pws_cnt * iter_part); - double speed_ms; - - hc_timer_get (device_param->timer_speed, speed_ms); + double speed_ms = hc_timer_get (device_param->timer_speed); const u32 speed_pos = device_param->speed_pos; @@ -1304,9 +1302,7 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co * speed */ - double speed_ms; - - hc_timer_get (device_param->timer_speed, speed_ms); + double speed_ms = hc_timer_get (device_param->timer_speed); hc_timer_set (&device_param->timer_speed); diff --git a/src/status.c b/src/status.c index e53cff5a1..155dd7f53 100644 --- a/src/status.c +++ b/src/status.c @@ -602,17 +602,13 @@ void status_display (status_ctx_t *status_ctx, opencl_ctx_t *opencl_ctx, const h * timers */ - double ms_running = 0; - - hc_timer_get (status_ctx->timer_running, ms_running); + double ms_running = hc_timer_get (status_ctx->timer_running); double ms_paused = status_ctx->ms_paused; if (status_ctx->devices_status == STATUS_PAUSED) { - double ms_paused_tmp = 0; - - hc_timer_get (status_ctx->timer_paused, ms_paused_tmp); + double ms_paused_tmp = hc_timer_get (status_ctx->timer_paused); ms_paused += ms_paused_tmp; } diff --git a/src/thread.c b/src/thread.c index 2d87f41a6..919e09452 100644 --- a/src/thread.c +++ b/src/thread.c @@ -186,9 +186,7 @@ void ResumeThreads (status_ctx_t *status_ctx) { if (status_ctx->devices_status != STATUS_PAUSED) return; - double ms_paused; - - hc_timer_get (status_ctx->timer_paused, ms_paused); + double ms_paused = hc_timer_get (status_ctx->timer_paused); status_ctx->ms_paused += ms_paused; diff --git a/src/timer.c b/src/timer.c index d00b4718a..9c3c43bbe 100644 --- a/src/timer.c +++ b/src/timer.c @@ -4,4 +4,43 @@ */ #include "common.h" +#include "types.h" #include "timer.h" + +#if defined (_WIN) + +inline void hc_timer_set (hc_timer_t *a) +{ + QueryPerformanceCounter (a); +} + +inline double hc_timer_get (hc_timer_t a) +{ + hc_timer_t hr_freq; + + QueryPerformanceFrequency (&hr_freq); + + hc_timer_t hr_tmp; + + hc_timer_set (&hr_tmp); + + return (double) ((double) (hr_tmp.QuadPart - a.QuadPart) / (double) (hr_freq.QuadPart / 1000)); +} + +#elif defined(_POSIX) + +inline void hc_timer_set (hc_timer_t* a) +{ + gettimeofday (a, NULL); +} + +inline double hc_timer_get (hc_timer_t a) +{ + hc_timer_t hr_tmp; + + hc_timer_set (&hr_tmp); + + return (double) (((hr_tmp.tv_sec - (a).tv_sec) * 1000) + ((double) (hr_tmp.tv_usec - (a).tv_usec) / 1000)); +} + +#endif