in reply to Python regex faster than Perl?

Thanks for the input, everyone. I'm quite new to Perl, I picked it up only a few months ago, as a replacement scripting language for bash. So I thought there must be something I'm missing. But it seems this might just be the way it is.

It's quite the shame that Perl has been dethroned in the dynamic language game when it comes to regex performance. Python's re module even implements Perl regex! It's a shame.

Thanks. -- Dave

Replies are listed 'Best First'.
Re^2: Python regex faster than Perl?
by Fletch (Bishop) on Mar 27, 2025 at 16:31 UTC

    It implements a subset.</nitpick> You can't use e.g. (?{ CODE }) for example, but unless you're doing dark wizardry (or you're Abigail, BIRM . . .) most things will be close.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re^2: Python regex faster than Perl?
by GrandFather (Saint) on Mar 30, 2025 at 20:27 UTC

    Writing off a language on the basis of a single flavor of benchmark yielding modest time differences isn't really sensible. In the vast majority of cases finding a language you are comfortable using and that does what you need fast enough to suit the task at hand is much more important than finding a tool that runs a specific task a little faster.

    Note that "comfortable using" extends beyond just you sitting in a dark room coding. It extends to being able to get help when you need it. For that, Perl and PerlMonks leads the field. Sure, there are sites like Stack Overflow, but I haven't found a PerlMonks equivalent site for any other language.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

      I agree with you, but this comes off as quite a defensive response :P. You don't need to sell me on Perl, I already am sold.

      Perl is stronger at regex and that's the perception of it that I've had for long before I even thought to learn it. In a bullet-point list of Perl's strengths, it'll always come up. It also seems that Perl has had a reputation, in the past, of performing faster than Python (and Ruby). Given this I'm sure you'd understand why I found it surprising that Python performs better in all the simple regex cases I tried.

      edit: I'm not sure about community support for Python, though it does seem stronger to me than you give it credit for. But I'll say that I certainly haven't found Perl lacking and I appreciate PerlMonks.

      Thanks. -- David

Re^2: Python regex faster than Perl?
by LanX (Saint) on Mar 30, 2025 at 03:13 UTC
    > Python's re module even implements Perl regex!

    Nope. There are a lot of features you won't find in Python or PCRE (and occasionally vice versa.)

    There are also examples where Sed dethrones Perl, it's a question of use case.

    There are also pathological cases of Regexes (with nested quantifiers) which never terminate in one engine but quickly yield results in another.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

Re^2: Python regex faster than Perl?
by bliako (Abbot) on Mar 30, 2025 at 21:12 UTC

    Hold your horses Dave! I am not absolutely convinced that the assumption that Python's regex engine is faster than Perl's has been conclusively proven, with benchmarks which take into consideration the 2nd point made by ikegami and the point made by Arunbear. Unless there is a report somewhere?