getOwnPropertyNames vs keys (v4)

Revision 4 of this benchmark created on


Description

Get the size of an hash.

Setup

"use strict";
    
    var keys = Object.keys
    ,   getOwnPropertyNames = Object.getOwnPropertyNames
    , defObj = {a:true, b:true, c:[1,2,3], spoke:{a:true}};
    
    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
defObj.getOwnPropertyNames().length
ready
Object.keys
Object.keys(defObj).length
ready
for .. in
oldWay(defObj).length
ready

Revisions

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