1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-22 14:48:12 +00:00

Replaced timer macros with inlines

This commit is contained in:
jsteube 2016-10-01 12:55:39 +02:00
parent ac3b850e40
commit 743dba56db
6 changed files with 47 additions and 29 deletions

View File

@ -6,16 +6,7 @@
#ifndef _TIMER_H #ifndef _TIMER_H
#define _TIMER_H #define _TIMER_H
#if defined (_WIN) void hc_timer_set (hc_timer_t *a);
double hc_timer_get (hc_timer_t a);
#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
#endif // _TIMER_H #endif // _TIMER_H

View File

@ -291,9 +291,7 @@ static void monitor (hashcat_ctx_t *hashcat_ctx)
if (status_ctx->devices_status == STATUS_PAUSED) if (status_ctx->devices_status == STATUS_PAUSED)
{ {
double ms_paused_tmp = 0; double ms_paused_tmp = hc_timer_get (status_ctx->timer_paused);
hc_timer_get (status_ctx->timer_paused, ms_paused_tmp);
ms_paused += ms_paused_tmp; ms_paused += ms_paused_tmp;
} }

View File

@ -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); const u64 perf_sum_all = (u64) (pws_cnt * iter_part);
double speed_ms; double speed_ms = hc_timer_get (device_param->timer_speed);
hc_timer_get (device_param->timer_speed, speed_ms);
const u32 speed_pos = device_param->speed_pos; 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 * speed
*/ */
double speed_ms; double speed_ms = hc_timer_get (device_param->timer_speed);
hc_timer_get (device_param->timer_speed, speed_ms);
hc_timer_set (&device_param->timer_speed); hc_timer_set (&device_param->timer_speed);

View File

@ -602,17 +602,13 @@ void status_display (status_ctx_t *status_ctx, opencl_ctx_t *opencl_ctx, const h
* timers * timers
*/ */
double ms_running = 0; double ms_running = hc_timer_get (status_ctx->timer_running);
hc_timer_get (status_ctx->timer_running, ms_running);
double ms_paused = status_ctx->ms_paused; double ms_paused = status_ctx->ms_paused;
if (status_ctx->devices_status == STATUS_PAUSED) if (status_ctx->devices_status == STATUS_PAUSED)
{ {
double ms_paused_tmp = 0; double ms_paused_tmp = hc_timer_get (status_ctx->timer_paused);
hc_timer_get (status_ctx->timer_paused, ms_paused_tmp);
ms_paused += ms_paused_tmp; ms_paused += ms_paused_tmp;
} }

View File

@ -186,9 +186,7 @@ void ResumeThreads (status_ctx_t *status_ctx)
{ {
if (status_ctx->devices_status != STATUS_PAUSED) return; if (status_ctx->devices_status != STATUS_PAUSED) return;
double ms_paused; double ms_paused = hc_timer_get (status_ctx->timer_paused);
hc_timer_get (status_ctx->timer_paused, ms_paused);
status_ctx->ms_paused += ms_paused; status_ctx->ms_paused += ms_paused;

View File

@ -4,4 +4,43 @@
*/ */
#include "common.h" #include "common.h"
#include "types.h"
#include "timer.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