You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that String.startsWith can be very slow for large strings when the str does not contain the prefix. The reason being the function actually does a str.indexOf call which will go through the entire function as long as it doesn't find anything.
So I tried benchmarking alternatives.
I tried using the ES2015 startsWith, which is by far faster but doesn't work on IE.
And I also tried another version where we slice the string and compare that to the prefix.
I noticed that
String.startsWith
can be very slow for large strings when the str does not contain the prefix. The reason being the function actually does astr.indexOf
call which will go through the entire function as long as it doesn't find anything.So I tried benchmarking alternatives.
I tried using the ES2015
startsWith
, which is by far faster but doesn't work on IE.And I also tried another version where we slice the string and compare that to the prefix.
Benchmark
Chrome
Firefox
What do you think of the idea of replacing
String.startsWith
? Does that sound good?Maybe we can do something faster in JS where we compare every character one by one.
I also think similar improvements can be made for
String.endsWith
.The text was updated successfully, but these errors were encountered: