Skip to content

Instantly share code, notes, and snippets.

@ConorOBrien-Foxx
Created October 4, 2017 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ConorOBrien-Foxx/821a3983d4aeaf2bd620990c1070039d to your computer and use it in GitHub Desktop.
Save ConorOBrien-Foxx/821a3983d4aeaf2bd620990c1070039d to your computer and use it in GitHub Desktop.
#ifndef INCLUDE_MILLISECONDS
#define INCLUDE_MILLISECONDS
#include <time.h>
#ifdef __WIN32
#include <windows.h>
#define M_OS_WINDOWS
#else
#include <sys/time.h>
#define M_OS_SANE
#endif
uint64_t milliseconds(void) {
#ifdef M_OS_WINDOWS
SYSTEMTIME time;
GetSystemTime(&time);
return (time.wSecond * 1000) + time.wMilliseconds;
#endif
#ifdef M_OS_SANE
struct timeval te;
gettimeofday(&te, NULL);
return te.tv_sec * 1000 + te.tv_usec / 1000;
#endif
}
#endif
#include "milliseconds.h"
int main() {
printf("%llu", milliseconds());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment