HTML Preparation code:
x
 
1
2
<script src='https://unpkg.com/jquery@3.5.1/dist/jquery.min.js'></script>
3
<script src='https://unpkg.com/jquery-once@2.2.3/jquery.once.min.js'></script>
4
<!-- IE Polyfills -->
5
<script>String.prototype.repeat||(String.prototype.repeat=function(t){"use strict";if(null==this)throw new TypeError("can't convert "+this+" to object");var e=""+this;if((t=+t)!=t&&(t=0),t<0)throw new RangeError("repeat count must be non-negative");if(t==1/0)throw new RangeError("repeat count must be less than infinity");if(t=Math.floor(t),0==e.length||0==t)return"";if(e.length*t>=1<<28)throw new RangeError("repeat count must not overflow maximum string size");var r=e.length*t;for(t=Math.floor(Math.log(t)/Math.log(2));t;)e+=e,t-=1;return e+=e.substring(0,r-e.length)}),Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector);</script>
6
<script src='https://unpkg.com/once-dom@3.5.0/dist/once.min.js'></script>
7
  
8
<div id="wrapper"></div>
Script Preparation code:
 
var totalDivs = 10, totalOnce = 3;
var wrapper = document.querySelector('#wrapper');
var $wrapper = jQuery(wrapper);
// uglysauce to make it work on IE11
var params = parent.window.location.search.replace('?', '').split('&');
params.forEach(function (par) { 
  var d = par.split('=');
  if (d[0] === 'div') { totalDivs = parseInt(d[1]); }
  if (d[0] === 'once') { totalOnce = parseInt(d[1]); }
})
wrapper.innerHTML = '<div class="test"></div>'.repeat(totalDivs); 
// Add some info in the test name to be able to compare things
var extra = ' (div=' + totalDivs + ', once=' + totalOnce + ')';
var newjQo = 'jQuery.once ' + extra;
var newO =  'once ' + extra;
parent.document.querySelector('[data-row-for^="jQuery.once"]').setAttribute('data-row-for', newjQo);
parent.document.querySelector('[data-row-for^="once"]').setAttribute('data-row-for', newO);
// Change the test names in the string that will be eval'ed right after this one.
content = content.replace("'jQuery.once'", "'" + newjQo + "'").replace("'once'", "'" + newO + "'");
Tests:
  • jQuery.once

     
    for (var i = 0; i < totalOnce; i++) {
      $wrapper.find('.test').once('test' + i);
    }
  • once

     
    for (var i = 0; i < totalOnce; i++) {
      once('test' + i, '.test', wrapper);
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    jQuery.once
    once

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
Chrome 116 on Linux
View result in a separate tab
Test name Executions per second
jQuery.once (div=10, once=1) 74483.4 Ops/sec
once (div=10, once=1) 199400.2 Ops/sec