jQuery Filter (Sizzle) Vs. Slice

Benchmark created on


Preparation HTML

<div class="section">Section 1</div>
<div class="section">Section 2</div>
<div class="section">Section 3</div>
<div class="section">Section 4</div>
<div class="section">Section 5</div><script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script>
  var $sections = $('.section');
  function randomFromTo(from, to){
      return Math.floor(Math.random() * (to - from + 1) + from);
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
filter()
var l = randomFromTo(0, 4);
$sections.filter(':lt('+l+')');
ready
slice()
var l = randomFromTo(0, 4);
$sections.slice(0, l);
ready

Revisions

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