Run details:
Mozilla/5.0 (X11; Linux x86_64; rv:137.0) Gecko/20100101 Firefox/137.0
Firefox 137
Linux
Desktop
2 months ago
Test name Executions per second
defineProperty 41508.1 Ops/sec
direct assign 98650.8 Ops/sec
Script Preparation code:
x
 
const val_obj = {
    value: null,
    configurable: true,
    enumerable: true,
    writable: true
};
function val(value) {
    val_obj.value = value;
    return val_obj;
}
Tests:
  • defineProperty

     
    let key = 'something';
    const target = {};
    for (let i=0; i<1000; i++) Object.defineProperty(target, i, val(key+i));
  • direct assign

     
    let key = 'something';
    const target = {};
    for (var i=0; i<1000; i++) target[i] = key+i;