kandi X-RAY | herodotus Summary
kandi X-RAY | herodotus Summary
A blazing-fast documentation site generator. 📖
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of herodotus
herodotus Key Features
herodotus Examples and Code Snippets
Community Discussions
Trending Discussions on herodotus
QUESTION
Link to jsperf if you prefer its formatting : https://jsperf.com/test-array-vs-loop-vs-loop-optimized
I was trying an old jsperf loop vs filter, and I tried to optimize the loop by preallocating the array if a correct size and avoiding item length recalculation. Issue is it didn't run faster on my Chrome 60.
Here is the code :
...ANSWER
Answered 2017-Sep-03 at 23:27I tried to optimize the loop by preallocating the array if a correct size
But you failed at that. The filter result usually doesn't have the same size as the input. By not appending to the array at its end (using push
) and assigning to the index i
always, you even were creating a sparse array. (Given your very small sample, it didn't have a large impact at least).
A correct approach might be
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install herodotus
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page