window.innerWidth vs document.body.clientWidth

JavaScript performance comparison

Revision 9 of this test case created by Ramiro Aisen

Preparation code

<script src="//code.jquery.com/jquery-2.0.3.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    // Jörg Schaper
    var $w = window;
    var $d = $w.document;
    var $b = $d.body;
   
    var v = 1024;
   
   
   
};
</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
window.innerWidth
var w = window.innerWidth;
pending…
document.body.clientWidth
var w = document.body.clientWidth;
pending…
$w.innerWidth
var w = $w.innerWidth;
pending…
$b.clientWidth
var w = $b.clientWidth;
pending…
$w["innerWidth"]
var w = $w["innerWidth"];
pending…
$b["clientWidth"]
var w = $b["clientWidth"];
pending…
jQuery
$(window).innerWidth()
pending…
jQuery2
$(window).width()
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