innerHeight vs $.fn.height()

Benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  $window = jQuery(window)
  $win = jQuery(window)
  $win.width = function() {
   return window.innerWidth;
  }
  $win.height = function() {
   return window.innerHeight;
  }
  
  A = {
   B: {
    height: $win.height(),
    width: $win.width()
   }
  }
  
  $win.cachedHeight = function() {
   return A.B.height;
  }
  
  $win.cachedWidth = function() {
   return A.B.width;
  }
  
  
  (function() {
   var width = A.B.width;
   var height = A.B.height;
   $win.cWidth = function() {
    return width;
   }
   $win.cHeight = function() {
    return height;
   }
  })();
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery
var x = jQuery(window).height();
var y = jQuery(window).width();
ready
direct
var a = window.innerHeight;
var b = window.innerWidth;
ready
cached window
var c = $window.height();
var d = $window.width()
ready
overwritten methods
var q = $win.height();
var r = $win.width()
ready
cached values
var w = $win.cachedHeight();
var h = $win.cachedWidth()
ready
closure
var cw = $win.cHeight();
var ch = $win.cWidth()
ready

Revisions

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