offsetWidth

JavaScript performance comparison

Test case created by Moncader

Preparation code

<div id="template">This is a test to see if this works.</div>
<div id="container"></div>

<script>
var template = document.getElementById("template");
var mContainer = document.getElementById("container");

for (var i = 0; i < 10; i++) {
  var temp = template.cloneNode(true);
  for (var j = 0; j < 100; j++) {
    temp.appendChild(template.cloneNode(true));
  }
  mContainer.appendChild(temp);
}
</script>
    

Preparation code output

<div id="template">This is a test to see if this works.</div> <div id="container"></div>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
No cache
var tContainer = mContainer;
var tWidth = 0;
for (var i = 0; i < 5000; i++) {
  tWidth += tContainer.offsetWidth;
}
pending…
Cache
var tContainer = mContainer;
var tWidth = 0;
var tCache = {
  offsetWidth: tContainer.offsetWidth
};
for (var i = 0; i < 5000; i++) {
  tWidth += tCache.offsetWidth;
}
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.

0 Comments

This is a test to see if this works.