gpt4 book ai didi

python - 是否有 Perl 的 `study` 的 Python 等效项?

转载 作者:太空狗 更新时间:2023-10-30 01:47:02 24 4
gpt4 key购买 nike

来自 Perl 的 documentation :

study takes extra time to study SCALAR ($_ if unspecified) in anticipation of doing many pattern matches on the string before it is next modified. This may or may not save time, depending on the nature and number of patterns you are searching and the distribution of character frequencies in the string to be searched;

我正在尝试加快我在 Python 中执行的一些正则表达式驱动的解析,我想起了 Perl 的这个技巧。我意识到我必须进行基准测试以确定是否有加速,但我在 Python 中找不到等效的方法。

最佳答案

Perl 的学习已经没什么用了。编译的正则表达式比创建 study 时更智能。

例如,它将备选方案编译成具有 Aho-Corasick 预测的 trie 结构。

使用 perl -Mre=debug 运行以查看正则表达式编译器和执行引擎应用的各种智能。

关于python - 是否有 Perl 的 `study` 的 Python 等效项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9574196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com