Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void match_with_regexp()
- {
- std::fstream f{ R"(C:\Users\Rapeity\Downloads\Telegram Desktop\qwe.trace)", std::ios::in };
- std::list<std::string> container;
- for (std::string line; std::getline(f, line); )
- {
- container.emplace_back(line);
- }
- static const std::regex regexp{ "(^Ljava.*)|(^Lcom\/google.*)|(^Landroid.*)" };
- clock_t before = clock();
- size_t count = 0;
- for (const auto& line : container)
- {
- if (std::regex_match(line, regexp))
- {
- ++count;
- }
- }
- clock_t difference = clock() - before;
- auto msec = difference * 1000 / CLOCKS_PER_SEC;
- printf("Took %ld for regexp\n", msec);
- printf("Found: %d\n", count);
- }
- void match_with_string()
- {
- std::fstream f{ R"(C:\Users\Rapeity\Downloads\Telegram Desktop\qwe.trace)", std::ios::in };
- std::list<std::string> container;
- for (std::string line; std::getline(f, line); )
- {
- container.emplace_back(line);
- }
- static const std::string prefixes[]
- {
- "Ljava",
- "Lcom\/google",
- "Landroid",
- };
- clock_t before = clock();
- size_t count = 0;
- for (const auto& line : container)
- {
- for (const auto& pref : prefixes)
- {
- if (line.size() >= pref.size() && !line.compare(0, pref.size(), pref))
- {
- ++count;
- }
- }
- }
- clock_t difference = clock() - before;
- auto msec = difference * 1000 / CLOCKS_PER_SEC;
- printf("Took %ld for strings\n", msec);
- printf("Found: %d\n", count);
- }
- int main()
- {
- match_with_regexp();
- match_with_string();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement