Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win timing test PR #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions run.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,9 @@ int argmax(float* v, int n) {
// ----------------------------------------------------------------------------

long time_in_ms() {
#if defined _WIN32
// windows specific way to get time
return GetTickCount();
#else
// linux specific way to get time
struct timespec time;
clock_gettime(CLOCK_REALTIME, &time);
return time.tv_sec * 1000 + time.tv_nsec / 1000000;
#endif
}

int main(int argc, char *argv[]) {
Expand Down
8 changes: 8 additions & 0 deletions win.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,11 @@ int munlock(const void *addr, size_t len)

return -1;
}

// Portable clock_gettime function for Windows
int clock_gettime(int clk_id, struct timespec *tp) {
DWORD ticks = GetTickCount();
tp->tv_sec = ticks / 1000;
tp->tv_nsec = (ticks % 1000) * 1000000;
return 0;
}
11 changes: 8 additions & 3 deletions win.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <time.h>


// Below code is originally from mman-win32
Expand All @@ -12,9 +13,9 @@
* mman-win32
*/

#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif

/* All the headers include this file. */
#ifndef _MSC_VER
Expand Down Expand Up @@ -47,12 +48,16 @@ extern "C" {
#define MS_SYNC 2
#define MS_INVALIDATE 4

/* Flags for portable clock_gettime call. */
#define CLOCK_REALTIME 0

void* mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off);
int munmap(void *addr, size_t len);
int mprotect(void *addr, size_t len, int prot);
int msync(void *addr, size_t len, int flags);
int mlock(const void *addr, size_t len);
int munlock(const void *addr, size_t len);
int clock_gettime(int clk_id, struct timespec *tp);

#ifdef __cplusplus
};
Expand Down