“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 your contribution.
I was curious about your suggestion and created a performance test on hasty.dev. When I run the tests on Chrome and Safari the original version is faster for me.
Do you mind taking a look?
On Chrome - the two methods are practically neck and neck. On Firefox, the second one is consistently faster, but not by a huge amount. The second should logically be faster as it performs 1 less loop than the one with the initial 0.
“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
On the link above (all tests on my macbook) - Chrome has near identical speed for both functions (occasionally the first will be faster than the other, but also sometimes the second). On Firefox, the second function is always faster. So, on balance it seems that without initialising the 0 is faster overall (as logically expected). The JS engine in Chrome is clearly doing some smarter optimisation
Update: Just tried Chrome and Firefox on Ubuntu too - same results as for the macbook
“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
Hi Randy,
thank you for your contribution.
I was curious about your suggestion and created a performance test on hasty.dev. When I run the tests on Chrome and Safari the original version is faster for me.
Do you mind taking a look?
Cheers,
Martin
The code editing on Hasty is really buggy too
On Chrome - the two methods are practically neck and neck. On Firefox, the second one is consistently faster, but not by a huge amount. The second should logically be faster as it performs 1 less loop than the one with the initial 0.
Performance Link
Logically yes, but it's like 10% faster - also at the url you set up - with an initial 0 for me.
On the link above (all tests on my macbook) - Chrome has near identical speed for both functions (occasionally the first will be faster than the other, but also sometimes the second). On Firefox, the second function is always faster. So, on balance it seems that without initialising the 0 is faster overall (as logically expected). The JS engine in Chrome is clearly doing some smarter optimisation
Update: Just tried Chrome and Firefox on Ubuntu too - same results as for the macbook
Hmm ... let's say ... we'll just go with the logic and I'll update the article and the code. :D
Thank you for your time and investigations.