Backreferences vs. Long RegExps

Benchmark created on


Setup

var backreferencesRegExp = /<(div|section|footer|input)[\s\S]*?<\/\1>/g;

var explicitCaseRegExp = /<div[\s\S]*?<\/div>|<section[\s\S]*?<\/section>|<footer[\s\S]*?<\/footer>|<input[\s\S]*?<\/input>/g;

var sampleString = `<div id="hs_cos_wrapper_homepage_page_header" class="hs_cos_wrapper hs_cos_wrapper_widget hs_cos_wrapper_type_module" style="" data-hs-cos-general-type="widget" data-hs-cos-type="module">



  
  
  

  
  
  

  
  
  
  
  
  
  <section class="wf-section wf-page-header -neutral -padding-top-md -padding-bottom-md">
    <div class="wf-section-wrapper">
      
    <div class="wf-page-header__wrapper">

      <div class="wf-page-header__content-wrapper">
        
          <p class="wf-page-header__tagline -microheading">HUBSPOT CUSTOMER PLATFORM</p>
        

        

  
    <h1 class="wf-page-header__heading -neutral -display ">Grow better with HubSpot</h1>
  



        
          <p class="wf-page-header__description">Software that's powerful, not overpowering. Seamlessly connect your data, teams, and customers on one AI-powered customer platform that grows with your business.</p>
        

        
          <div class="wf-page-header__cta-wrapper">
            
              

  
  

  
    
  

  
  
  
    
    
    
      <a class="
  cl-button -primary -large wf-page-header__cta homepage-hero-cta" href="https://offers.hubspot.com/crm-platform-demo?hubs_signup-url=www.hubspot.com&amp;hubs_signup-cta=homepage-hero-cta" rel="noreferrer ">
        Get a demo
        
          <span class="visually-hidden">of HubSpot's premium software</span>
        
        
      </a>
    
  
  

            
              

  
  

  
    
  

  
  
  
    
    
    
      <a class="
  cl-button -secondary -large wf-page-header__cta homepage-hero2-cta" href="https://app.hubspot.com/signup-hubspot/crm?hubs_signup-url=www.hubspot.com&amp;hubs_signup-cta=homepage-hero2-cta" rel="noreferrer ">
        Get started free
        
          <span class="visually-hidden">with HubSpot's free tools</span>
        
        
      </a>
    
  
  

            
          </div>
        

        
          <p class="wf-page-header__disclaimer -small">Get a demo of our premium software, or get started with free tools.</p>
        
      </div>

      
        <div class="wf-page-header__image-wrapper ">
          
          
          <img src="https://knowledge.hubspot.com/hs-fs/hubfs/homepage-hero-ai.webp?width=1824&amp;height=1266&amp;name=homepage-hero-ai.webp" fetchpriority="high" class="wf-page-header__image" alt="HubSpot interfaces showing Your Weekly Activity with email, call, and meeting counts. Repurpose your content with Content Remix and HubSpot AI. AI Chatbot: Want to chat? I'm an AI chatbot here to help you find your way. A business contact's name, photo, and how to contact them." width="1824" height="1266" srcset="https://knowledge.hubspot.com/hs-fs/hubfs/homepage-hero-ai.webp?width=912&amp;height=633&amp;name=homepage-hero-ai.webp 912w, https://knowledge.hubspot.com/hs-fs/hubfs/homepage-hero-ai.webp?width=1824&amp;height=1266&amp;name=homepage-hero-ai.webp 1824w, https://knowledge.hubspot.com/hs-fs/hubfs/homepage-hero-ai.webp?width=2736&amp;height=1899&amp;name=homepage-hero-ai.webp 2736w, https://knowledge.hubspot.com/hs-fs/hubfs/homepage-hero-ai.webp?width=3648&amp;height=2532&amp;name=homepage-hero-ai.webp 3648w, https://knowledge.hubspot.com/hs-fs/hubfs/homepage-hero-ai.webp?width=4560&amp;height=3165&amp;name=homepage-hero-ai.webp 4560w, https://knowledge.hubspot.com/hs-fs/hubfs/homepage-hero-ai.webp?width=5472&amp;height=3798&amp;name=homepage-hero-ai.webp 5472w" sizes="(max-width: 1824px) 100vw, 1824px">
        </div>
      

    </div>
  
    </div>
  </section>


</div>`;

Teardown

backreferencesRegExp.startIndex = 0;
explicitCaseRegExp.startIndex = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
Backreferences
while (backreferencesRegExp.exec(sampleString)) {}
ready
Explicit Choice RegExp
while (explicitCaseRegExp.exec(sampleString)) {}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.