define-property-enumerable

Benchmark created by Ray Cromwell on


Description

Measure the effect of setting enumerable on a property.

Setup

var nextId = 0;
    var sum = 0;
    
    Object.defineProperty(Object.prototype, "$H", 
           { enumerable: false, configurable: true, 
             setter: function() {},
             get: function () { 
               var hash = nextId++;
               Object.defineProperty(this, "$H", {
                 enumerable: false, writable: false, configurable: false,
                 value: hash,
               }); 
               return hash;
            }
           });

Teardown


    window.__sum = sum;
  

Test runner

Ready to run.

Testing in
TestOps/sec
Enumerable Field
var o = {};
var hash = o.$J || (o.$J = nextId++);
sum += o.$J;
ready
Non-Enumerable Field
var obj2 = {};
sum += obj2.$H;
ready
Enumerable Keys
var obj = {};
sum += Object.getOwnPropertyNames(obj).length;
ready
Non-enumerable keys
var obj = {};
sum += Object.getOwnPropertyNames(obj).length;
ready

Revisions

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

  • Revision 1: published by Ray Cromwell on