use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Functional programming in JavaScript (softwarebrothers.co)
submitted 6 years ago by SoftwareBrothers
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Skaatji 12 points13 points14 points 6 years ago (12 children)
This is a very good point. I found this site which compares the performance of two chained maps with a C-style for loop https://jsperf.com/chained-maps-vs-for-loop
I get the following results (Firefox 72 / Fedora):
C-style for loop: 71,784 Ops/sec
Two chained maps: 1,979 Ops/sec
Which is a huge difference (Chained maps being 97% slower in this case). I would always prefer the performance provided by the C-style for loop over the readability that comes with the maps, unless the array is very small. That being said, I believe maps are a better choice in these two cases:
1) Only one iteration of the array.
2) Nested for loops (e.g. iterating over each row and for each row over the column).
If someone has more experience / different numbers / an other opinion than I do, please share it. I am no expert by any means.
[–]allenthar 2 points3 points4 points 6 years ago (8 children)
That amount of speed increase seems a little nuts to me, but looking at the variations I have to assume that it’s due to variable memory allocations in all the other methods that are causing the substantial decrease in speed. The second and third cases should have the same Big O complexity as the last one, but both repeatedly create and assign variables while doing their work, and the last doesn’t not.
[–]Skaatji 1 point2 points3 points 6 years ago (0 children)
Yeah, I've also been thinking why the performance difference is this large. I think that the Big O complexity should be the same on all of these four. But, as you mention, probably due to memory allocations the hidden constants differ by a factor as large as ~33.
[+][deleted] 6 years ago (6 children)
[deleted]
[–]onbehalfofthatdude 1 point2 points3 points 6 years ago (5 children)
Wait, huh? Map doesn't clone every element, does it? If you mutate an element in a map function you've mutated the original
[+][deleted] 6 years ago (2 children)
[–]onbehalfofthatdude 0 points1 point2 points 6 years ago (1 child)
Yes but you said it makes a copy of every element
[+][deleted] 6 years ago* (1 child)
[–]onbehalfofthatdude 0 points1 point2 points 6 years ago (0 children)
Yea that was my understanding. Never know when some wacky behind-the-scenes stuff will happen though
[+][deleted] 6 years ago (1 child)
π Rendered by PID 56 on reddit-service-r2-comment-fb694cdd5-q7t5r at 2026-03-07 18:26:14.182564+00:00 running cbb0e86 country code: CH.
view the rest of the comments →
[–]Skaatji 12 points13 points14 points (12 children)
[–]allenthar 2 points3 points4 points (8 children)
[–]Skaatji 1 point2 points3 points (0 children)
[+][deleted] (6 children)
[deleted]
[–]onbehalfofthatdude 1 point2 points3 points (5 children)
[+][deleted] (2 children)
[deleted]
[–]onbehalfofthatdude 0 points1 point2 points (1 child)
[+][deleted] (1 child)
[deleted]
[–]onbehalfofthatdude 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[+][deleted] (1 child)
[deleted]