access variables/properties (v2)

Revision 2 of this benchmark created by alpicola on


Preparation HTML

<script>
  var _v = 10;
  var test = {
   v: 10,
   local_variable: function() {
    var v = 10,
        n = 100000;
    while (--n) v + n;
   },
   semilocal_variable: (function() {
    var v = 10;
    return function() {
     var n = 100000;
     while (--n) v + n;
    };
   })(),
   global_variable: function() {
    var n = 100000;
    while (--n) _v + n;
   },
   this_property: function() {
    var n = 100000;
    while (--n) this.v + n;
   },
   obj_property: function() {
    var obj = {
     v: 10
    };
    var n = 100000;
    while (--n) obj.v + n;
   },
   prototype_property: function() {
    function constructor() {};
    constructor.prototype.v = 10;
    var obj = new constructor();
    var n = 100000;
    while (--n) obj.v + n;
   },
   proto_property: function() {
    var obj = {};
    obj.__proto__ = {
     v: 10
    };
    var n = 100000;
    while (--n) obj.v + n;
   }
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
local variable
test.local_variable();
ready
semi local variable
test.semilocal_variable();
ready
global variable
test.global_variable();
ready
this property
test.this_property();
ready
obj property
test.obj_property();
ready
prototype property
test.prototype_property();
ready
__proto__ property
test.proto_property();
ready

Revisions

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