Which one has better performance when both Reflect.ownKeys and Object.keys can be used?

in other words, the bottom layer first obtains Reflect.ownKeys , and then excludes inenumerable ones, thus getting the result of Object.keys .

or is there a special acceleration channel for the acquisition of enumerable attributes, while Reflect.ownKeys is slower because it appears late and is not fully optimized?

Mar.03,2022

run in chrome console:

var obj = {};
for(var i=0;i<10000;iPP){obj[i] = i;obj[Symbol(i)] = i;} // add 10000 properties and 10000 symbol properties
// call the method 1000 times
console.time("Reflect.ownKeys");
for(var i=0;i<1000;iPP){
  Reflect.ownKeys(obj);
}
console.timeEnd("Reflect.ownKeys");
// Reflect.ownKeys: 3666.298095703125ms

console.time("Object.getOwnPropertyNames");
for(var i=0;i<1000;iPP){
  Object.getOwnPropertyNames(obj);
}
console.timeEnd("Object.getOwnPropertyNames");
// Object.getOwnPropertyNames: 1003.471923828125ms

but when the symbol attribute is not added, the time consumption is the same

Menu