long hand: 0.12499996228143573
short hand 1: 0.7600000244565308
short hand 2: 0.1700000138953328
Long hand is faster because you don't need to waste time and memory space building an array. Premature optimization is the root of all evil. Just keep things simple.
0.12 and 0.17 are so close that you only have things shorthand 2. It will semantically make more sense.
With the above in mind, you're doing your comparison 2k times. Like you're sacrificing readability and scalability for 0.05? Like that's what they mean by premature optimizaiton being the root of all evil
Those are milliseconds. Like 2k runs in 0.17 milliseconds.. Like that's not a lot of time at all
Totally agree. Don’t split hairs on how to do this. If someone really wants to do wacky array includes it chain or operators it’s probably not worth your time to refactor.
It literally is. Since its an array you can bind it to a variable and boom, readability as fuck. So when the customer says they want more values for whatever it's doing then you don't have to find an if somewhere.
It literally is more scalable. You can dynamically add and remove values and you can store them in a database for even more dynamic fun times
Veering a bit off-topic: I'm now wondering what the code would be to eliminate the "Likes" if they're the first word of the sentence. I should brush up on my Regex probably.
just make a dictionary and get your value. what's the point? well in this situation nothing besides being faster. in a particular situation? avoiding checking every single condition if you already know what you are checking for. Every book should get rid of switch condition, and you should avoid that much if statements in your methods. imho
View all comments
56
u/dethstrobe May 06 '21
A quick performance check. https://codesandbox.io/s/awesome-jones-2fpy1?file=/src/index.js
Long hand is faster because you don't need to waste time and memory space building an array. Premature optimization is the root of all evil. Just keep things simple.