Replies: 11 comments
-
much Ops/sec 🐶 @dodieboy
|
Beta Was this translation helpful? Give feedback.
-
sadly include() do not accept regex as argument so indexOf() is the faster way for regex search |
Beta Was this translation helpful? Give feedback.
-
It look like include() is slower on string compare to using it on array. The longer the string you search, the speed have a bigger different comapre to indexof which the speed is more sable. |
Beta Was this translation helpful? Give feedback.
-
hi @dodieboy!
Now, shall we run this change on all javascript in the world? |
Beta Was this translation helpful? Give feedback.
-
Yup, it will really optimize the code if we are able to apply it too all codes |
Beta Was this translation helpful? Give feedback.
-
Hey @dodieboy why close?☺ |
Beta Was this translation helpful? Give feedback.
-
cant think of any better way to optimize the code, will reopen when I have the time to research new ways |
Beta Was this translation helpful? Give feedback.
-
Oh, I moved it to this repo because it potentially applies to all JS in every (public) project. Thus it stays worth reading. hopefully there is a lot to come in this repo. Hope you like that. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hey, I will like to suggest to use includes() instate of indexOf() in your code when you are checking if the item exist. include() will be better in that case as you do not use the return int value of indexOf(), all you want is true or false which is what include() return.
Since it return true or false, equal operator is not needed (improve performance) and it is a Boolean (1 bit) which use lesser memory compare to int which is 16 bit.
Here is a performance test that I did: https://www.measurethat.net/Benchmarks/ShowResult/215464
Beta Was this translation helpful? Give feedback.
All reactions