window.innerWidth vs document.body.clientWidth

JavaScript performance comparison

Revision 6 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.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…
1024
var w = 1024;
pending…
v
// Jörg Schaper
var w = v;
pending…
$w.innerWidth
// Jörg Schaper
var w = $w.innerWidth;
pending…
$b.clientWidth
// Jörg Schaper
var w = $b.clientWidth;
pending…
$w["innerWidth"]
// Jörg Schaper
var w = $w["innerWidth"];
pending…
$b["clientWidth"]
// Jörg Schaper
var w = $b["clientWidth"];
pending…
jQuery
$(window).innerWidth()
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