Regular expression : non capturing groups are faster ?

Devin Jeanpierre jeanpierreda at gmail.com
Tue Jan 3 15:38:36 EST 2012


> I tested 10 million matches on my computer using capturing groups and it took ~ 6 seconds, but only ~ 2 seconds with non-capturing params.

Are you talking about Python or Perl? I can't reproduce this in
Python. Best I can do is a 3:4 ratio between running times. ('(a)*
versus '(?:a)*)

Also, wouldn't say "very fast". Compare those two groups with 'a*'.
I'm not sure what's going on there.

-- Devin

On Tue, Jan 3, 2012 at 3:07 PM, Octavian Rasnita <orasnita at gmail.com> wrote:
> From: "Devin Jeanpierre" <jeanpierreda at gmail.com>
> Subject: Re: Regular expression : non capturing groups are faster ?
>
>
>>> You meant Perl Documentation, didn't you ?
>>
>> I guess that works too. I did mean Python, though -- its intent is to
>> say "you shouldn't worry about this", but in the process it says "this
>> does not exist" (a lie).
>
>
> **
> However, the Perl documentation doesn't lie.
>
> I tested 10 million matches on my computer using capturing groups and it took ~ 6 seconds, but only ~ 2 seconds with non-capturing params.
>
> So yes, it is very fast anyway, but ~ 3 times faster with non-capturing params, so there is a difference.
>
> Octavian
>
> --
> http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list