2
我试图测试正则表达式的捕获组和非捕获组的性能。顺便说一下,捕获组和非捕获组之间的差别很小。 这个结果是否正常?捕获组VS未捕获组
[[email protected] ~]# ll -h sample.log
-rw-r--r-- 1 root root 21M Oct 20 23:01 sample.log
[[email protected] ~]# time grep -ciP '(get|post).*' sample.log
20000
real 0m0.083s
user 0m0.070s
sys 0m0.010s
[[email protected] ~]# time grep -ciP '(?:get|post).*' sample.log
20000
real 0m0.083s
user 0m0.077s
sys 0m0.004s
非捕获组需要一点点的时间比捕获组,因为没有文本被保存在缓存。 –
如果您希望节省时间,请去除'。*',因为它总是匹配的,而且您没有捕获它。 –