如何检查Apache RewriteRule正则表达式的性能 - 速度?那有什么工具吗?

时间:2022-01-19 11:19:23

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?

但有没有办法检查和比较它(Apache RewriteRule正则表达式)的正确性能?

1 个解决方案

#1


3  

Apache regex seems to be derived from PCRE so you can probably use pcretest to benchmark and get a clue how they perform.

Apache正则表达式似乎源自PCRE,因此您可以使用pcretest进行基准测试并获得它们的执行方式。

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.

以下是使用一百万个测试匹配和三个不同测试输入对两个表达式进行计时的结果。输出是每场比赛的平均执行时间。

$ pcretest -tm 1000000 -q
  re> /^([a-z]{2,8})$/
data> a
Execute time 0.0002 milliseconds
No match
data> aaaaaaaa
Execute time 0.0003 milliseconds
 0: aaaaaaaa
 1: aaaaaaaa
data> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Execute time 0.0006 milliseconds
No match
data> 

$ pcretest -tm 1000000 -q
  re> /^(.*)$/
data> a
Execute time 0.0003 milliseconds
 0: a
 1: a
data> aaaaaaaa
Execute time 0.0003 milliseconds
 0: aaaaaaaa
 1: aaaaaaaa
data> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Execute time 0.0005 milliseconds
 0: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 1: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
data> 

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?

它们似乎具有相似的执行时间,在我的测试机器上每秒大约2-3百万次匹配。但真正的问题是,为什么你怀疑重写规则的匹配时间是个问题?

#1


3  

Apache regex seems to be derived from PCRE so you can probably use pcretest to benchmark and get a clue how they perform.

Apache正则表达式似乎源自PCRE,因此您可以使用pcretest进行基准测试并获得它们的执行方式。

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.

以下是使用一百万个测试匹配和三个不同测试输入对两个表达式进行计时的结果。输出是每场比赛的平均执行时间。

$ pcretest -tm 1000000 -q
  re> /^([a-z]{2,8})$/
data> a
Execute time 0.0002 milliseconds
No match
data> aaaaaaaa
Execute time 0.0003 milliseconds
 0: aaaaaaaa
 1: aaaaaaaa
data> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Execute time 0.0006 milliseconds
No match
data> 

$ pcretest -tm 1000000 -q
  re> /^(.*)$/
data> a
Execute time 0.0003 milliseconds
 0: a
 1: a
data> aaaaaaaa
Execute time 0.0003 milliseconds
 0: aaaaaaaa
 1: aaaaaaaa
data> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Execute time 0.0005 milliseconds
 0: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 1: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
data> 

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?

它们似乎具有相似的执行时间,在我的测试机器上每秒大约2-3百万次匹配。但真正的问题是,为什么你怀疑重写规则的匹配时间是个问题?