
Ask HN: Why is Array.from so slow? - cfv
I made this benchmark  here: https:&#x2F;&#x2F;jsperf.com&#x2F;ways-to-get-a-random-string<p>And I lack the formal knowledge to understand why the Array.from version is about 25% as fast as the while loop version, being that they intuitively should do something similar.<p>Can you please help me understand?
======
username90
Array.from makes an extra function call each iteration and function calls are
very expensive in interpreted languages. Compilers or interpreters sometimes
optimizes it away, but in this case it didn't.

Remember this: Compiler optimizations are very unreliable, small innocuous
changes in code can get huge effects on performance.

Edit: Just looked at the code in the link, and Array.from is not the only
difference, the other code uses string concatenation instead of array
concatenation. Appending to a string in Javascript is typically a lot faster
than appending to an array.

~~~
handoff
> Appending to a string in Javascript is typically a lot faster than appending
> to an array.

The same is true in C# if I recall correctly. Not sure if that’s still the
case

