Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. #include <locale>
  5. #include <algorithm>
  6.  
  7. //code GetTimeMs64() coped from stackoverflow.
  8. #ifdef _WIN32
  9. #include <Windows.h>
  10. #else
  11. #include <sys/time.h>
  12. #include <ctime>
  13. #endif
  14.  
  15. /* Remove if already defined */
  16. typedef long long int64; typedef unsigned long long uint64;
  17.  
  18. /* Returns the amount of milliseconds elapsed since the UNIX epoch. Works on both
  19. * windows and linux. */
  20.  
  21. uint64 GetTimeMs64()
  22. {
  23. #ifdef _WIN32
  24. /* Windows */
  25. FILETIME ft;
  26. LARGE_INTEGER li;
  27.  
  28. /* Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC) and copy it
  29. * to a LARGE_INTEGER structure. */
  30. GetSystemTimeAsFileTime(&ft);
  31. li.LowPart = ft.dwLowDateTime;
  32. li.HighPart = ft.dwHighDateTime;
  33.  
  34. uint64 ret = li.QuadPart;
  35. ret -= 116444736000000000LL; /* Convert from file time to UNIX epoch time. */
  36. ret /= 10000; /* From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals */
  37.  
  38. return ret;
  39. #else
  40. /* Linux */
  41. struct timeval tv;
  42.  
  43. gettimeofday(&tv, NULL);
  44.  
  45. uint64 ret = tv.tv_usec;
  46. /* Convert from micro seconds (10^-6) to milliseconds (10^-3) */
  47. ret /= 1000;
  48.  
  49. /* Adds the seconds (10^0) after converting them to milliseconds (10^-3) */
  50. ret += (tv.tv_sec * 1000);
  51.  
  52. return ret;
  53. #endif
  54. }
  55.  
  56. bool is_a_num(char c)
  57. {
  58. return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
  59. }
  60.  
  61. int main()
  62. {
  63. std::string str(100000000, '_');
  64. for(char& c : str) {
  65. //this basicialyl alwas returns a valdi chracter, this is needed suhc that
  66. //c = 'a' + rand() % 20;
  67. c = rand() % 250;
  68. }
  69. auto time1 = GetTimeMs64();
  70. bool isvalid = true;
  71. int validcount = 0;
  72. for(char c : str) {
  73. validcount += std::isalnum((c), std::locale::classic()) ? 1 : 0;
  74. //validcount += is_a_num(c) ? 1 : 0;
  75. }
  76.  
  77. auto time2 = GetTimeMs64();
  78. std::cout << "Hello, " << time2 - time1 << "," << validcount << "!\n";
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement