如何检查 Apache RewriteRule 正则表达式性能 - 速度?有什么工具可以做到这一点吗?
举个简单的例子,很容易理解规则
RewriteRule ^([a-z]{2,8})$ ?id=$1 [L,QSA]
比
RewriteRule ^(.*)$ ?id=$1 [L,QSA]
但有什么方法可以检查和比较其(Apache RewriteRule regex)的正确性能吗?
For easy example it is easy understandable that rule
RewriteRule ^([a-z]{2,8})$ ?id=$1 [L,QSA]
is faster than
RewriteRule ^(.*)$ ?id=$1 [L,QSA]
But is there any way to check and compare its (Apache RewriteRule regex) correct performance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Apache regex 似乎是 源自 PCRE 所以你可以使用
pcretest
进行基准测试并了解它们的性能。以下是使用一百万个测试匹配和三个不同的测试输入对两个表达式进行计时的结果。输出是每场比赛的平均执行时间。
它们的执行时间似乎相似,在我的测试机器上每秒大约 2-3 百万个匹配。但真正的问题是,为什么你怀疑重写规则的匹配时间是个问题?
Apache regex seems to be derived from PCRE so you can probably use
pcretest
to benchmark and get a clue how they perform.Here are the results when timing the two expressions using one million test matches and three different test inputs. Outputting is average execution time for each match.
They seem to have similar execution times, around 2-3 million matches per second on my test machine. But the real questions is, why do you suspect that the matching time for the rewrite rules are a problem?