jQuery: Cost of testing opacity in the hidden filter (v2)

Revision 2 of this benchmark created by lonesomeday on


Description

http://bugs.jquery.com/ticket/9336

Preparation HTML

<div id="a"></div>
<div id="b"></div>
<div id="c"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  jQuery.expr.filters.realhidden = function(elem) {
   var width = elem.offsetWidth,
       height = elem.offsetHeight;
  
   return (width === 0 && height === 0) || (!jQuery.support.reliableHiddenOffsets && (elem.style.display || jQuery.css(elem, "display")) === "none" && (elem.style.opacity || jQuery.css(elem, "opacity")) === "0");
  };
  jQuery('#a').css({
   opacity: 0
  });
  jQuery('#b').css({
   opacity: 100
  });
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Existing (no opacity check)
jQuery('#a').is(':hidden');
jQuery('#b').is(':hidden');
jQuery('#c').is(':hidden');
ready
Added opacity check
jQuery('#a').is(':realhidden');
jQuery('#b').is(':realhidden');
jQuery('#c').is(':realhidden');
ready

Revisions

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

  • Revision 2: published by lonesomeday on