4 ms·
Is it actually any faster? Let's see... https://jsperf.com/trimcall/1 https://jsperf.com/trimcall/1 For me, the "clever" one is slightly faster in Chrome whil
by tomatsu 9y ago
Is it actually any faster? Let's see...
https://jsperf.com/trimcall/1 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.)
- cominous 9y agoCan confirm this. Clever version is actually about 10% faster with node v9.1
- cominous 9y agoActually, 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%