filter method to filter from already cached selector

JavaScript performance comparison

Test case created by Sudhanshu Yadav

Preparation code

  <style>
    .imp{color:red}
  </style>
  <span class="number imp">1</span>

  <span class="number">2</span>

  <span class="number gt2">3</span>

  <span class="number imp  gt2">4</span>

  <span class="number gt2">5</span>

  <span class="number gt2">6</span>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 

Preparation code output

1 2 3 4 5 6

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
using selectors for filter
  $(".number").removeClass("imp");

  $(".number.gt2").addClass("imp");

  $(".number:contains(1)").addClass("imp");

 
pending…
filter using cached selectors
 var number=$(".number");

  number.removeClass("imp");

  number.filter(".gt2").addClass("imp");

number.filter(":contains(1)").addClass("imp");
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