Javascript is fast. Really fast - at least if it´s running in a modern browser. So, in general you should not care too much about performance. But ...
For further actions, you may consider blocking this person and/or reporting abuse
Not sure how these results are obtained. Maybe you should also publish the code you used to test.
I Tried to reproduce using the information you gave us and with a few new approaches: see this snippet. The results are different.
Results will greatly depend on your machine and the browser. I added my test code at the end of the post so you can try the tests I did.
Right, so you're telling us you tested a text with 4625 lines, but in the snippet you are testing a text with 251 lines - the result of which you use here.
Oh, sorry, my fault! 4625 was the file length, not the line count. I changed the text, thank you for the hint!
You will find that results will greatly change on different machines. On and Intel(R) Core(TM) i7-1185G7 for..of was the winner, but the speed factor was only 2.7 to the slowest result.
Ok, both cases are now covered in my snippet. And yes, it (ofcourse) also depends on the used hardware.
BTW I would advice to always use semicolons for line ends in EcmaScript.
I have done a lot coding in C and Pascal, but did not miss the semicolons for any reason. Beside of personal taste, is there any technical reason to use semicolons?
Most of the time it's not relevant. I've coded
Java/ECMAScript since its conception (besides pascal, c, c++ and c#). Still every now and then I run into a problem because of the interpreters' automatic semicolon insertion *). So I force myself to use them.*) for example
Maybe
Might be worth a try, too.
In my setup regEx-replace was about 20% slower than the slowest solution, which is still not bad. Things might change if the task get´s more complicated, but in general I found that regEx performance is quite reasonable, Not top of the list, but also not much slower than hand optimized code. If you take into account that RegEx expressions can be quite complex, this is still an amazing result.
Thank you for the hint, I´ll add this to the post.
Yes 'good old loop performs much better' ;-)
VERY insightful post. Performance testing under a particular workload is a great way to ensure more positive UX.
Sure, but we should also look for the numbers. A delay of 50 ms will hardly be recognized by the user, which could mean:
Often it is not easy to find the reason for slow interactions. Doing things as simple as possible could be a good advice to reduce workload.
Yep.. small changes, big results.