habr_dom_access (v2)

Revision 2 of this benchmark created on


Description

test dom acces by azproduction

Preparation HTML

<div id='pewpew'></div>
<script>
  var getter = function(a) {
   return document.getElementById(a);
  },
      globalVar = Math.random();
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
normal model
document.getElementById('pewpew');
ready
closured
(function(window, document) {
 document.getElementById('pewpew');
}(this, this.document));
ready
normal x100
for (var i = 0, l = 500; l; --l, ++i) {
 document.getElementById('pewpew');
}
ready
clusure x10
(function(window, document) {
 for (var i = 0, l = 500; l; --l, ++i) {
  document.getElementById('pewpew');
 }
}(this, this.document));
ready
normal x100 g
for (var i = 0, l = 500; l; --l, ++i) {
 getter('pewpew');
}
ready
clusure x10 g
(function(window, document, getter) {
 for (var i = 0, l = 500; l; --l, ++i) {
  getter('pewpew');
 }
}(this, this.document, getter));
ready
[A] normal globalVar
for (var i = 0, l = 500, tmp; l; --l, ++i) {
 tmp = globalVar * 2;
}
ready
[A] clusure globalVar
(function(window, document, globalVar) {
 for (var i = 0, l = 500, tmp; l; --l, ++i) {
  tmp = globalVar * 2;
 }
}(this, this.document, globalVar));
ready

Revisions

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