6b11404dd2f0

JavaScript performance comparison

Test case created by multiple selector vs single selector

Preparation code

<table id="table">
  <tr>
    <a href=""></a>
  </tr>
  <tr>
    <a href=""></a>
  </tr>
  <tr>
    <a href=""></a>
  </tr>
  <tr>
    <a href=""></a>
  </tr>
  <tr>
    <a href=""></a>
  </tr>
  <tr>
    <a href=""></a>
  </tr>
</table>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
Benchmark.prototype.setup = function() {
    var nth = [1, 2, 3, 4, 5];
};
</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
multiple
$("#table tr *:nth-child(1)").css("display", "none");
$("#table tr *:nth-child(2)").css("display", "none");
$("#table tr *:nth-child(3)").css("display", "none");
$("#table tr *:nth-child(4)").css("display", "none");
$("#table tr *:nth-child(5)").css("display", "none");
pending…
single
$('#table tr *')
  .filter(':nth-child(' + nth.join('),:nth-child(') + ')')
  .css('display', 'none');
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment