Split platform specific time measurement away
We now have a `stopwatch` to measure time between two moments.
This commit is contained in:
parent
a7a5e8cfad
commit
739f5d6d5c
3 changed files with 98 additions and 49 deletions
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
#include "compiler_specifics.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Error Reporting */
|
||||
|
||||
/* BSD errx function, seen in err.h */
|
||||
|
|
@ -15,4 +17,39 @@ H_MSVC_DECLSPEC(noreturn) \
|
|||
void h_platform_errx(int err, const char* format, ...) \
|
||||
H_GCC_ATTRIBUTE((noreturn, format (printf,2,3)));
|
||||
|
||||
/* Time Measurement */
|
||||
|
||||
struct HStopWatch; /* forward definition */
|
||||
|
||||
/* initialize a stopwatch */
|
||||
void h_platform_stopwatch_reset(struct HStopWatch* stopwatch);
|
||||
|
||||
/* return difference between last reset point and now */
|
||||
int64_t h_platform_stopwatch_ns(struct HStopWatch* stopwatch);
|
||||
|
||||
/* Platform dependent definitions for HStopWatch */
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
|
||||
struct HStopWatch {
|
||||
LARGE_INTEGER qpf;
|
||||
LARGE_INTEGER start;
|
||||
};
|
||||
|
||||
#else
|
||||
/* Unix like platforms */
|
||||
|
||||
#include <time.h>
|
||||
|
||||
struct HStopWatch {
|
||||
struct timespec start;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue