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
非捕獲組需要一點點的時間比捕獲組,因爲沒有文本被保存在緩存。 –
如果您希望節省時間,請去除'。*',因爲它總是匹配的,而且您沒有捕獲它。 –