re: How to reverse a string in JavaScript VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Have you looked at the performance impact of each method?
 

the first is the most straightforward, while the second is going to be the fastest by far compared to #1 and #3

 

the second is going to be the fastest by far compared to #1 and #3

No, it isn't. Symbol-by-symbol string concatenation comes with significant penalties outside of microbenchmarks that immediately throw the result out.

Perhaps, but reduce is more than a power of magnitude faster than split reverse join. It’s on jsperf

That microbench is taken out of context, «faster» there does not actually mean anything.

In an actual application where you would actually use the result instead of throwing it out immediately, char-by-char concatenation would consume up to an order of magnitude more memory and slow everything down.

My code to repoduce that is in a comment below, in another thread here.

code of conduct - report abuse