Hacker News new | ask | show | jobs
by tomatsu 3124 days ago
Is it actually any faster? Let's see...

https://jsperf.com/trimcall/1

For me, the "clever" one is slightly faster in Chrome while the supposedly naive one is significantly faster in Firefox.

Looks like the naive approach not only wins in terms of readability, but performance, too. (Unless I seriously screwed this up which is always a possibility with micro benchmarks.)

1 comments

Can confirm this. Clever version is actually about 10% faster with node v9.1
Actually, the for-based loop is another 10% faster - so if performance is relevant, just use the for-loop!

Node v9.1 + benchmark.js clever-solution x 249,543 ops/sec ±0.36% standard-arrow-function x 213,926 ops/sec ±0.35% old-for-loop x 261,449 ops/sec ±0.54%