“It’s only work if somebody makes you do it.” • craft code • creative ideas • cutting edge • author • senior front end architect • professional scuba diver • adventures above and below the sea level
Location
Germany
Work
Senior Front End Architect, Full Stack Engineer, Creative Technologist and Scuba Diving Professional
thank you for taking the time to contribute, I put both functions to the performance benchmark on hasty and I'm going to update the article with your suggestion!
+1 for this. I'll always prefer legible over performant unless dealing with code that absolutely requires performance. 99% of the time I'm dealing with small datasets so it isn't necessary. And as you've said below, v8 optimises a lot of these convenience methods.
Hello, World! I'm jzombie, a passionate software developer with a knack for problem-solving and a love for open-source. I believe in the power of code to change the world and make our lives easier.
“It’s only work if somebody makes you do it.” • craft code • creative ideas • cutting edge • author • senior front end architect • professional scuba diver • adventures above and below the sea level
Location
Germany
Work
Senior Front End Architect, Full Stack Engineer, Creative Technologist and Scuba Diving Professional
Hello, World! I'm jzombie, a passionate software developer with a knack for problem-solving and a love for open-source. I believe in the power of code to change the world and make our lives easier.
“It’s only work if somebody makes you do it.” • craft code • creative ideas • cutting edge • author • senior front end architect • professional scuba diver • adventures above and below the sea level
Location
Germany
Work
Senior Front End Architect, Full Stack Engineer, Creative Technologist and Scuba Diving Professional
Then at least use & instead of % if you care about performance. That difference can't be microoptimized, because the modulo requires float point handling, whereas the binary operation runs directly on the CPU.
“It’s only work if somebody makes you do it.” • craft code • creative ideas • cutting edge • author • senior front end architect • professional scuba diver • adventures above and below the sea level
Location
Germany
Work
Senior Front End Architect, Full Stack Engineer, Creative Technologist and Scuba Diving Professional
“It’s only work if somebody makes you do it.” • craft code • creative ideas • cutting edge • author • senior front end architect • professional scuba diver • adventures above and below the sea level
Location
Germany
Work
Senior Front End Architect, Full Stack Engineer, Creative Technologist and Scuba Diving Professional
Or you use the fastest possible version:
Hey!
thank you for taking the time to contribute, I put both functions to the performance benchmark on hasty and I'm going to update the article with your suggestion!
Cheers!
+1 for this. I'll always prefer legible over performant unless dealing with code that absolutely requires performance. 99% of the time I'm dealing with small datasets so it isn't necessary. And as you've said below, v8 optimises a lot of these convenience methods.
I would have thought filter was indeed slower, but not according to this.
It is one of the cases where performance really depends on the browser / javascript engine.
Agreed.
I tested it w/ Chrome, on Mac & Linux. Not sure how Safari / Firefox results may vary.
Appreciate the discussion. Going to use the filter version as I expect the other browsers / javascript engines to catch up in microoptimisations.
Then at least use
&instead of%if you care about performance. That difference can't be microoptimized, because the modulo requires float point handling, whereas the binary operation runs directly on the CPU.Hi Luke,
yes you are right :D Here is the updated benchmark on hasty - filter is much slower for me.
No, it isn't faster. Not sure what's wrong with your machine, but it's about 20-30% slower on any machine I tested it on.
I just ran that test and for was 20% faster on current Chrome.
Hi Luke,
you are right filter is more intuitive, but it is actually slower for me.
Cheers!