ID selector vs eq() from list

JavaScript performance comparison

Test case created by scarfaceDeb

Preparation code

<script src="">
<div id="steps">
Benchmark.prototype.setup = function() {
    var markup = '';
    for (var i = 1; i < 100; i++) {
      markup += '<p id="step' + i + '"><ul><li>123</li><li>123</li><li>123</li><li>123</li><li>123</li><li>123</li></ul></p>';
    var stepsCont = $('#steps');
    var steps = stepsCont.find('p');

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
ID from global scope
$('#step32').on('click', function() {});
$('#step32').off('click', function() {});
ID from local scope
$('#step32', stepsCont).on('click', function() {});
$('#step32', stepsCont).off('click', function() {});
eq() from list
steps.eq(31).on('click', function() {});
steps.eq(31).off('click', function() {});

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

Compare results of other browsers


Comment form temporarily disabled.

Add a comment