0
std::wregex EXCEL_CELL_REGEX(L"=\"(.*)\"", std::regex::optimize);
std::wstring text = L"=\"300498\"";
for (int i = 0; i < 981 * 6; i++) {
    std::wsmatch match;
    std::regex_match(text, match, EXCEL_CELL_REGEX);
}

Above code takes about 9 seconds

boost::wregex EXCEL_CELL_REGEX(L"=\"(.*)\"", boost::regex::optimize);
std::wstring text = L"=\"300498\"";
for (int i = 0; i < 981 * 6; i++) {
    boost::wsmatch match;
    boost::regex_match(text, match, EXCEL_CELL_REGEX);
}

Above code takes about 1.5 seconds


Those tests are built on Debug configuration.

Do you know why std::regex is so slow? How to optimize the code?

4
  • 8
    Use Release build for testing performance. Commented Jul 24, 2018 at 16:34
  • Debug build may add consistency check. Commented Jul 24, 2018 at 16:35
  • 7
    Never benchmark performance with debug builds. The code is not optimized by the compiler. There will be debug assertions (and more) active that are compiled out in release builds. Nobody actually cares about the performance of debug builds since that's never what you ship. Always benchmark optimized release builds. Commented Jul 24, 2018 at 16:57
  • You are right, after switching to Release build, it tasks less than 1 second now. Commented Jul 24, 2018 at 17:28

2 Answers 2

3

Debug execution times are useless; they are often completely divorced from real-life performance of the Release build. Also, debug times will be extremely system- and compiler-dependent.

Sign up to request clarification or add additional context in comments.

Comments

1

If you are using boost in debug configurations, you will got a lot of debug stuff who will probably don't need it. If you wish run in debug mode. Try look for memory and CPU snapshots to see where the bottleneck resides! I suggest you use the c++11 clock std lib functions to measure time elapsed with more precision.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.