getOwnPropertyNames vs keys

Benchmark created by FGRibreau on


Description

Get the size of an hash.

Setup

"use strict";
    
    var keys = Object.keys
    ,   getOwnPropertyNames = Object.getOwnPropertyNames;
    
    function oldWay(obj){
    var a = [];
    for(var prop in obj){
    if (obj.hasOwnProperty(prop)) {
    a.push(prop);
    }}
    return a;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Object.getOwnPropertyNames
getOwnPropertyNames({a:true, b:true, c:[1,2,3], spoke:{a:true}}).length
ready
Object.keys
keys({a:true, b:true, c:[1,2,3], spoke:{a:true}}).length
ready
for .. in
oldWay({a:true, b:true, c:[1,2,3], spoke:{a:true}}).length
ready

Revisions

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