Jump to content

[perf] Reading object properties vs Reading array fields


Ezelia
 Share

Recommended Posts

Hello all,

 

Just wanted to share with you a little test I made, don't know if it's representative ...

 

I allways thought that reading array fields was faster than reading object properties  (maybe because of "for(;;)" is faster than "for in" syntax) .
but I made a simple test with jsperf that gave me the opposite result : http://jsperf.com/object-prop-vs-array

 

can you confirm that with real life examples ?

 

 

 

Link to comment
Share on other sites

@mgutz actually it's not what's I'm saying here :)   a['foo'] is the exact equivalent of a.foo  I don't think you'll get any performance gaine here.
what I did in the example is comparing array of values for example [30, 30, 40, 22] to an object holding each value in a property, example {x:30, y:30, z:40, p:22}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...