MCPcopy Create free account
hub / github.com/ashvardanian/less_slow.cpp / parse_regex

Function parse_regex

less_slow.cpp:4570–4593  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4568}
4569
4570void parse_regex(bm::State &state, std::string_view config_text) {
4571 std::size_t pairs = 0, bytes = 0;
4572 std::vector<std::pair<std::string, std::string>> settings;
4573
4574 // Prefer multiline mode so ^ and $ anchor to line breaks...
4575 auto regex_options = std::regex_constants::ECMAScript;
4576 // ... but MSVC does not define `std::regex_constants::multiline` yet!
4577#if !defined(_MSC_VER)
4578 regex_options |= std::regex_constants::multiline;
4579#endif
4580 // Construct the regex only once. Compilation is expensive!
4581 // BTW, there is still no `std::string_view` constructor 🤦‍♂️
4582 std::regex regex_fsm(regex_for_config.data(), regex_for_config.size(), regex_options);
4583
4584 for (auto _ : state) {
4585 settings.clear();
4586 config_parse_regex(config_text, settings, regex_fsm);
4587 bm::DoNotOptimize(settings);
4588 pairs += settings.size();
4589 bytes += config_text.size();
4590 }
4591 state.SetBytesProcessed(bytes);
4592 state.counters["pairs/s"] = bm::Counter(pairs, bm::Counter::kIsRate);
4593}
4594
4595BENCHMARK_CAPTURE(parse_regex, short_, short_config_text)->MinTime(2);
4596BENCHMARK_CAPTURE(parse_regex, long_, long_config_text)->MinTime(2);

Callers

nothing calls this directly

Calls 2

config_parse_regexFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected