Advertisement
Rochet2

head

Sep 28th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "Header.h"
  3. #include <string>
  4. /*
  5. #include <algorithm>    // std::next_permutation, std::sort
  6. #include <assert.h>
  7. #include <bitset>
  8. #include <cstdlib>
  9. #include <iostream>
  10. #include <map>
  11. #include <memory>
  12. #include <mutex>
  13. #include <set>
  14. #include <sstream>
  15. #include <stdint.h>
  16. #include <stdio.h>
  17. #include <string>
  18. #include <unordered_map>
  19. #include <unordered_set>
  20. #include <vector>
  21. */
  22. #include <stdint.h>
  23.  
  24. typedef int64_t int64;
  25. typedef int32_t int32;
  26. typedef int16_t int16;
  27. typedef int8_t int8;
  28. typedef uint64_t uint64;
  29. typedef uint32_t uint32;
  30. typedef uint16_t uint16;
  31. typedef uint8_t uint8;
  32.  
  33. #define UNORDERED_MAP std::unordered_map
  34.  
  35. #ifdef WIN32
  36. #include <Windows.h>
  37. #else
  38. #include <sys/time.h>
  39. #include <ctime>
  40. #endif
  41. #undef max
  42.  
  43. // Returns the amount of milliseconds elapsed since the UNIX epoch. Works on both
  44. // windows and linux.
  45.  
  46. uint64 GetTimeMs64()
  47. {
  48. #ifdef _WIN32
  49.     // Windows
  50.     FILETIME ft;
  51.     LARGE_INTEGER li;
  52.  
  53.     // Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC) and copy it
  54.     // to a LARGE_INTEGER structure.
  55.     GetSystemTimeAsFileTime(&ft);
  56.     li.LowPart = ft.dwLowDateTime;
  57.     li.HighPart = ft.dwHighDateTime;
  58.  
  59.     uint64 ret = li.QuadPart;
  60.     ret -= 116444736000000000LL; // Convert from file time to UNIX epoch time.
  61.     ret /= 10000; // From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals
  62.  
  63.     return ret;
  64. #else
  65.     // Linux
  66.     struct timeval tv;
  67.  
  68.     gettimeofday(&tv, NULL);
  69.  
  70.     uint64 ret = tv.tv_usec;
  71.     // Convert from micro seconds (10^-6) to milliseconds (10^-3)
  72.     ret /= 1000;
  73.  
  74.     // Adds the seconds (10^0) after converting them to milliseconds (10^-3)
  75.     ret += (tv.tv_sec * 1000);
  76.  
  77.     return ret;
  78. #endif
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement