c++ - std::regex 在 VC2015U3 上比 boost::regex 慢得多

标签 c++ performance c++11 boost boost-regex

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);
}

以上代码大约需要 9

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);
}

以上代码大约需要 1.5


这些测试建立在调试配置之上。

你知道为什么 std::regex 这么慢吗?如何优化代码?

最佳答案

调试执行时间是无用的;它们通常与发布版本的实际性能完全脱节。此外,调试时间将极其依赖于系统和编译器。

关于c++ - std::regex 在 VC2015U3 上比 boost::regex 慢得多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51503590/

相关文章:

c++ - 关于在 C++ 中使用模板的指针数组

c++ - 将 C++ 数学函数扩展到非基本类型

c++ - G++ 不编译 C++0x 基于范围的 for 循环

performance - C++ - 最快的双线性插值?

c++ - 如何在函数参数初始化中捕获未定义的行为

c++ - execv() 和 const-ness

javascript - 空事件会减慢 Javascript 处理速度吗?

C++ 优化

.net - 最佳 JIT 优化

c++ - 为什么不允许仅对一个 ref-qualifier 进行重载?