ID selector vs eq() from list

JavaScript performance comparison

Test case created by scarfaceDeb

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="steps">
</div>
<script>
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>';
    }
    $('#steps').html(markup);
    var stepsCont = $('#steps');
    var steps = stepsCont.find('p');
};
</script>

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() {});
pending…
ID from local scope
$('#step32', stepsCont).on('click', function() {});
$('#step32', stepsCont).off('click', function() {});
pending…
eq() from list
steps.eq(31).on('click', function() {});
steps.eq(31).off('click', function() {});
pending…

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

Compare results of other browsers

0 comments

Add a comment