jquery visible test (v7)

Revision 7 of this benchmark created by Gupta on


Description

http://stackoverflow.com/questions/4696779/performance-of-jquery-visible

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="test-content"></div>
<script>
  $(function() {
   for (var i = 200; i--;) {
    $('<span />', {
     style: "display:" + ((i % 2) ? 'block' : 'none'),
     class: "test-span" + ((i % 2) ? ' visi' : ' notvisi'),
     text: i
    }).appendTo('#test-content');
   }
  });
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
:visible
var spans = $('.test-span:visible');
ready
normal
var spans = $('.test-span');
ready
two classes
var spans = $('.test-span.visi');
ready
two classes not
var spans = $('.test-span:not(.notvisi)');
ready
visibility css selector
var spans = $('.test-span').filter(":visible");
ready
select all and filter using foreach loop
var tempSpans = $('.test-span');
var spans = [];
tempSpans.each(function () {
                        if ($(this).is(":visible")) {
                                spans.push(this);
                        }
        })
ready

Revisions

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