loading...

re: Assigning [ ] performs better than Array(n) - Reports attached. VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Yes! this was really interesting to explore. I hadn't even considered the differences in browsers implementations. I still think it would be best...

May be not for now!

Though it looks like chrome is working on holey array performance, they haven't given a heads-up yet on safe usage of holey array.

You may want to go through it, It is a video done by one of v8 team member.
youtube.com/watch?time_continue=44...

I think there may have been a misunderstanding, I don't see why you wouldn't modify your post.

I haven't once argued that holey arrays are good or that there are no drawbacks (I even said in my original reply: "While the statements you are making are true, your example is still not entirely representative of this fact"). This whole time I've just been trying to point out the problems with the testing method. All I'm suggesting is utilizing the startup section of jsperf for a more honest test, like shown in jsperf.com/test-assign-vs-push/23

Currently your post is using a test where the main performance difference is the initialization of a large array and then joining said 2000 element array. compared to initializing an empty array and joining 20 elements.

Your most recent example is a much better showcase of the drawbacks of holey arrays.

Reversing the order of the tests reveals the opposite answer - I fear this is a jsPerf limitation. But again you have now made a weird array by adding values and not pushing for packed - so perhaps it's also a browser implementation of that which is giving you amazingly dramatically different results. Without the actual perf I can't see but 94% slower seems just very odd and certainly not inline with the one I link below in either case.

Screenshot

jsperf.com/testh-v-p

I already mentioned about chrome vs firefox. Please go through the entire thread before commenting.

Also, don't forget to watch the video that is posted at the end of article. It is by v8 team member. That should answer most of your questions if you won't trust on random tests.

I won't be able to respond on this post further if the video provided at the end of post is not watched. Thanks!

Code of Conduct Report abuse