2016-11-18 16:24:02 +0000, Stephane Chazelas: [...] > Why would it make it slower. AFAICT, PCRE_MULTILINE *adds* > some overhead. It is really meant to be only about changing the > behaviour of ^ and $. [...]
Unsurprisingly, where ~/a contains the output of find / -print0 (which is typically what grep -z is used on) 304MiB, 3696401 records, none of which contain a newline character in this instance. with grep 2.10 (Ubuntu 12.04 amd64) in a UTF-8 locale: $ time grep -Pz '(?-m)^/' ~/a > /dev/null grep -Pz '(?-m)^/' ~/a > /dev/null 0.84s user 0.15s system 99% cpu 0.990 total $ time grep -Pz '^/' ~/a > /dev/null grep -Pz '^/' ~/a > /dev/null 0.87s user 0.12s system 99% cpu 0.989 total Not much difference as "/" is found at the beginning of each record. $ time grep -Pz '(?-m)^x' ~/a > /dev/null grep -Pz '(?-m)^x' ~/a > /dev/null 0.41s user 0.06s system 99% cpu 0.473 total $ time grep -Pz '^x' ~/a > /dev/null grep -Pz '^x' ~/a > /dev/null 0.81s user 0.04s system 99% cpu 0.854 total PCRE_MULTILINE significantly slows things down as even though "x" is not found at the beginning of the subject, grep still needs to look for extra newline characters in the record. -- Stephane