Attribute selector vs Filter func

Benchmark created by Rory Mcrossan on


Preparation HTML

<script>
    
    for (var i = 0; i < 500; i++) {
    document.write("<div class="num" data-num='" + i + "'>" + i + "</div>\n");
    }
    
    </script>
  };
</script>

Setup

Benchmark.prototype.setup = function() {
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">

Test runner

Ready to run.

Testing in
TestOps/sec
Attribute selector
$('[data-num="300"]');
ready
Filter
$('.num').filter(function() {
   return $(this).data('num') == '300';
});
ready

Revisions

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

  • Revision 1: published by Rory Mcrossan on