SHARE
TWEET

Untitled

a guest Apr 26th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void match_with_regexp()
  2. {
  3.   std::fstream f{ R"(C:\Users\Rapeity\Downloads\Telegram Desktop\qwe.trace)", std::ios::in };
  4.  
  5.   std::list<std::string> container;
  6.  
  7.   for (std::string line; std::getline(f, line); )
  8.   {
  9.     container.emplace_back(line);
  10.   }
  11.  
  12.   static const std::regex regexp{ "(^Ljava.*)|(^Lcom\/google.*)|(^Landroid.*)" };
  13.  
  14.   clock_t before = clock();
  15.  
  16.   size_t count = 0;
  17.   for (const auto& line : container)
  18.   {
  19.     if (std::regex_match(line, regexp))
  20.     {
  21.       ++count;
  22.     }
  23.   }
  24.   clock_t difference = clock() - before;
  25.   auto msec = difference * 1000 / CLOCKS_PER_SEC;
  26.  
  27.   printf("Took %ld for regexp\n", msec);
  28.   printf("Found: %d\n", count);
  29. }
  30.  
  31. void match_with_string()
  32. {
  33.   std::fstream f{ R"(C:\Users\Rapeity\Downloads\Telegram Desktop\qwe.trace)", std::ios::in };
  34.  
  35.   std::list<std::string> container;
  36.  
  37.   for (std::string line; std::getline(f, line); )
  38.   {
  39.     container.emplace_back(line);
  40.   }
  41.  
  42.   static const std::string prefixes[]
  43.   {
  44.     "Ljava",
  45.     "Lcom\/google",
  46.     "Landroid",
  47.   };
  48.  
  49.   clock_t before = clock();
  50.  
  51.   size_t count = 0;
  52.   for (const auto& line : container)
  53.   {
  54.     for (const auto& pref : prefixes)
  55.     {
  56.       if (line.size() >= pref.size() && !line.compare(0, pref.size(), pref))
  57.       {
  58.         ++count;
  59.       }
  60.     }
  61.   }
  62.   clock_t difference = clock() - before;
  63.   auto msec = difference * 1000 / CLOCKS_PER_SEC;
  64.  
  65.   printf("Took %ld for strings\n", msec);
  66.   printf("Found: %d\n", count);
  67. }
  68.  
  69. int main()
  70. {
  71.   match_with_regexp();
  72.   match_with_string();
  73.   return 0;
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top