std :: regex_constants :: optimize使用的优化技术 [英] Optimization techniques used by std::regex_constants::optimize

查看:65
本文介绍了std :: regex_constants :: optimize使用的优化技术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 std :: regex ,并且在阅读有关 std :: regex_constants 中定义的各种常量的同时,我遇到了 std :: optimize,仔细阅读它,听起来对我的应用程序很有用(我只需要一个regex实例,该实例在开始时已初始化,但是在整个加载过程中使用了多次).

I am working with std::regex, and whilst reading about the various constants defined in std::regex_constants, I came across std::optimize, reading about it, it sounds like it is useful in my application (I only need one instance of the regex, initialized at the beginning, but it is used multiple times throughout the loading process).

根据工作论文n3126 (第1077页), std :: regex_constants :: optimize :

According to the working paper n3126 (pg. 1077), std::regex_constants::optimize:

指定正则表达式引擎应更加注意正则表达式的匹配速度,而应较少关注正则表达式对象的构建速度.否则,它对程序输出没有可检测的影响.

Specifies that the regular expression engine should pay more attention to the speed with which regular expressions are matched, and less to the speed with which regular expression objects are constructed. Otherwise it has no detectable effect on the program output.

我对执行哪种类型的优化感到好奇,但是关于它的文献似乎很少(事实上,它似乎是未定义的),而我发现的唯一一件事是在 cppreference.com ,其中指出 std :: regex_constants :: optimize :

I was curious as to what type of optimization would be performed, but there doesn't seem to be much literature about it (indeed, it seems to be undefined), and one of the only things I found was at cppreference.com, which stated that std::regex_constants::optimize:

指示正则表达式引擎使匹配更快,而使构造变慢的潜在成本.例如,这可能意味着将非确定性FSA转换为确定性FSA.

Instructs the regular expression engine to make matching faster, with the potential cost of making construction slower. For example, this might mean converting a non-deterministic FSA to a deterministic FSA.

但是,我没有计算机科学的正式背景,虽然我了解FSA是什么的基础知识,并且了解确定性FSA(每个状态只有一个可能的下一个状态)之间的基本区别,并且非确定性FSA(具有多个潜在的下一个状态);我不明白这会如何增加匹配时间.另外,我想知道各种C ++标准库实现中是否还有其他优化.

However, I have no formal background in computer science, and whilst I'm aware of the basics of what an FSA is, and understand the basic difference between a deterministic FSA (each state only has one possible next state), and a non-deterministic FSA (with multiple potential next states); I do not understand how this improves matching time. Also, I would be interested to know if there are any other optimizations in various C++ Standard Library implementations.

推荐答案

There's some useful information on the topic of regex engines and performance trade offs (far more than can fit in a stackoverflow answer) in Mastering Regular Expressions by Jeffrey Friedl.

值得注意的是,作为N3126的源的Boost.Regex将 optimize 记录为这目前对Boost.Regex无效".

It's worth noting that Boost.Regex, which was the source for N3126, documents optimize as "This currently has no effect for Boost.Regex."

P.S.

实际上,这似乎是实现定义的

indeed, it seems to be implementation-defined

否,未指定.实现定义的是指需要来定义行为的选择.无需实现即可记录其正则表达式引擎的实现方式或 optimize 标志产生的差异(如有).

No, it's unspecified. Implementation-defined means an implementation is required to define the choice of behaviour. Implementations are not required to document how their regex engines are implemented or what (if any) difference the optimize flag makes.

P.S.2

在各种STL实现中

in various STL implementations

std :: regex 不是STL的一部分,C ++标准库与STL不同.

std::regex is not part of the STL, the C++ Standard Library is not the same thing as the STL.

这篇关于std :: regex_constants :: optimize使用的优化技术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆