Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3346714
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:20:11+00:00 2026-05-18T01:20:11+00:00

In the English module and a few other places, users are advised never to

  • 0

In the English module and a few other places, users are advised never to use the $& $` and $' variables or their English equivalents $MATCH $PREMATCH $POSTMATCH due to the fact that they will slow down all regex use.

What is a good test case (benchmark) that shows the performance problems?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:20:12+00:00Added an answer on May 18, 2026 at 1:20 am

    Here’s a simple starting point, looking for a single character in strings of varying lengths. The match variables make copies of the source string so I expected the penalty to be proportional to the amount of copying required. Reality seems to be the opposite. (This is why we benchmark, children.) The cost of matching against a longer string outweighs the overhead of making a copy. In retrospect, that makes sense, as the copy is just a memcpy while the regex engine has to scan character-by-character.

    use 5.010;
    use strict;
    use warnings;
    use Benchmark qw(cmpthese);
    
    for my $n (map { 10 ** $_ } 0 .. 4) {
        my $string = 'a' x $n . 0 . 'a' x $n;
    
        print "N = $n:\n";
        cmpthese(1000000, {
            'w/ match vars'  => sub { $string =~ /\d/p },
            'w/o match vars' => sub { $string =~ /\d/  },
        });
        print "\n";
    }
    

    Results:

    N = 1:
                (warning: too few iterations for a reliable count)
                        Rate  w/ match vars w/o match vars
    w/ match vars  1184834/s             --           -54%
    w/o match vars 2557545/s           116%             --
    
    N = 10:
                        Rate  w/ match vars w/o match vars
    w/ match vars  1164144/s             --           -49%
    w/o match vars 2283105/s            96%             --
    
    N = 100:
                        Rate  w/ match vars w/o match vars
    w/ match vars   865052/s             --           -45%
    w/o match vars 1560062/s            80%             --
    
    N = 1000:
                       Rate  w/ match vars w/o match vars
    w/ match vars  224568/s             --           -21%
    w/o match vars 284333/s            27%             --
    
    N = 10000:
                      Rate  w/ match vars w/o match vars
    w/ match vars  26667/s             --           -15%
    w/o match vars 31480/s            18%             --
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an easy-to-use python module that'd do english or finnish text validation? It'd
I realize there have been a few other questions on this topic, and the
If you're not a native English speaker doing Drupal, then the i18n module is
I'm setting a site up with EE2 in a language other than English that
first, sorry about my english, i still learning. I writing Python module for my
I wanted to upgrade the Magento Ogone module to match the new SHASign calculation.
I have a problem with swfobject_api or jwplayer module When i use this code
Modules or software solutions for generating English pronounceable passwords? Are there similar modules for
English, of course, is a no-brainer for regex because that's what it was originally
In English or US keyboards keys like \ , / , [ and ]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.