On Tue, Feb 14, 2012 at 3:25 AM, Jimb Esser <[email protected]> wrote:

> I keep reading things saying "Object.keys is much faster than
> for..in", but in most tests I do (and in a bunch I find on
> jsperf.com), that is the opposite of the case.
>

There are two big differences:

1) for..in walks the prototype chain, while Object.keys() does not.
2) for..in is dynamic in that it detects keys that are deleted during the
loop.

For objects with very few properties and very shallow prototype chains,
for..in may be faster. As the number of properties and/or the depth of the
prototype chain grows, Object.keys() will get faster.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to