Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- #include <locale>
- #include <algorithm>
- //code GetTimeMs64() coped from stackoverflow.
- #ifdef _WIN32
- #include <Windows.h>
- #else
- #include <sys/time.h>
- #include <ctime>
- #endif
- /* Remove if already defined */
- typedef long long int64; typedef unsigned long long uint64;
- /* Returns the amount of milliseconds elapsed since the UNIX epoch. Works on both
- * windows and linux. */
- uint64 GetTimeMs64()
- {
- #ifdef _WIN32
- /* Windows */
- FILETIME ft;
- LARGE_INTEGER li;
- /* Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC) and copy it
- * to a LARGE_INTEGER structure. */
- GetSystemTimeAsFileTime(&ft);
- li.LowPart = ft.dwLowDateTime;
- li.HighPart = ft.dwHighDateTime;
- uint64 ret = li.QuadPart;
- ret -= 116444736000000000LL; /* Convert from file time to UNIX epoch time. */
- ret /= 10000; /* From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals */
- return ret;
- #else
- /* Linux */
- struct timeval tv;
- gettimeofday(&tv, NULL);
- uint64 ret = tv.tv_usec;
- /* Convert from micro seconds (10^-6) to milliseconds (10^-3) */
- ret /= 1000;
- /* Adds the seconds (10^0) after converting them to milliseconds (10^-3) */
- ret += (tv.tv_sec * 1000);
- return ret;
- #endif
- }
- bool is_a_num(char c)
- {
- return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
- }
- int main()
- {
- std::string str(100000000, '_');
- for(char& c : str) {
- //this basicialyl alwas returns a valdi chracter, this is needed suhc that
- //c = 'a' + rand() % 20;
- c = rand() % 250;
- }
- auto time1 = GetTimeMs64();
- bool isvalid = true;
- int validcount = 0;
- for(char c : str) {
- validcount += std::isalnum((c), std::locale::classic()) ? 1 : 0;
- //validcount += is_a_num(c) ? 1 : 0;
- }
- auto time2 = GetTimeMs64();
- std::cout << "Hello, " << time2 - time1 << "," << validcount << "!\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement