Visible checkboxes

JavaScript performance comparison

Revision 2 of this test case created

Info

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

Preparation code

<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--;) {
   $('<input />', {
    style: "display:" + ((i % 2) ? 'block' : 'none'),
    class: "test-span" + ((i % 2) ? ' visi' : ' notvisi'),
    type: 'checkbox',
    checked: (Math.random() > 0.5)
   }).appendTo('#test-content');
  }
 });
</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
:visible
$('.test-span:visible').each(function() {
 if (this.checked);
});
pending…
2 classes
$('.test-span.visi').each(function() {
 if (this.checked);
});
pending…
jQuery.expr.filters.visible
$('.test-span').each(function() {
 if (this.checked && jQuery.expr.filters.visible(this)) {}
});
pending…
:checked:visible
$('.test-span:checked:visible').each(function() {

});
pending…
separate :visible
$('.test-span').has(':visible').each(function() {
 if (this.checked);
});
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