Another sample is array.push vs array.unshift, basically for memory reasons. If I remember correctly, a push is simple for most computers because it already has "extra" memory allocated at the end of an array, and will only have to recreate the array when the allocated memory runs out. unshift however will always recreate the whole array because adding an item to the start of an array would require moving ever single item one step. Recreating the whole array is simpler to do than moving each one.
Very thorough article.
Considering the fame of lodash, I now wonder is there's a place for an equivalent with performance in mind.
I also wonder how many more example like this is there is. Is that only
concator most ofArray.prototypethat can be optimized ?I remember my early struggles with JS performance, replacing
Math.floorby<< 0gaining considerable amount op/s. (Not true today)Another sample is
array.pushvsarray.unshift, basically for memory reasons. If I remember correctly, apushis simple for most computers because it already has "extra" memory allocated at the end of an array, and will only have to recreate the array when the allocated memory runs out.unshifthowever will always recreate the whole array because adding an item to the start of an array would require moving ever single item one step. Recreating the whole array is simpler to do than moving each one.See stackoverflow.com/questions/440315...
Huh, interesting!