mewt icon indicating copy to clipboard operation
mewt copied to clipboard

Benchmark diff implementations

Open sdgluck opened this issue 9 years ago • 6 comments

In #16 @bali182 discussed the various options for removing an element from an array by index. Would be nice to benchmark the different available approaches.

sdgluck avatar Mar 29 '17 08:03 sdgluck

@sdgluck any idea how we should go about this? I don't think this should live in this repo, but it would be nice to have this (among other things) tested in both various browsers and node. I tried jsPerf, but it's a mess, I couldn't even submit it, the server died on me before the tests were saved, after that the site wouldn't even load... Do you know of any tools that does this well? Google did not come up with much - at least not the first page :)

bali182 avatar Mar 29 '17 10:03 bali182

We could use https://benchmarkjs.com/ but that is something we have to run on our own possibly using travis together with the tests :(

bali182 avatar Mar 29 '17 10:03 bali182

I think having the benchmarks in the repository would be fine, under a benchmarks folder? That way they can be run through an npm script.

Benchmarks could be created using marky

sdgluck avatar Mar 29 '17 10:03 sdgluck

Sure, if you are OK with having in the repo :)

But regarding the tool for benchmarking, I don't think we should use a single run with a timer, that can be very circumstantial. I think we should use a benchmarking tool that runs each case a good number of times and draws the conclusion from that.

That's why I was looking at benchmark this seems to be the only benchmarking tool I could find for js, but not really sure how good or bad it is. I'll keep looking.

bali182 avatar Mar 29 '17 10:03 bali182

Managed to get jsPerf workinging: https://jsperf.com/remove-by-index-from-array

Results (quite suprising - at least for me) - slicing then concatenating seems to be the fastest on all platforms and browsers.

Windows/Chrome: jsperf-chrome-win

Windows/Firefox jsperf-firefox-win

Mac/Chrome jsperf-chrome-mac

Mac/Firefox jsperf-firefox-mac

bali182 avatar Mar 29 '17 13:03 bali182

Interesting results! Especially that Chrome seems to be significantly slower than Firefox in this regard.

sdgluck avatar Mar 30 '17 06:03 sdgluck

Remember, that most ES6+ features aren't yet optimized to their ES5 counterparts. Even introducing Babel to the mix can skew the results.

https://kpdecker.github.io/six-speed/#test-spread

sscotth avatar Apr 03 '17 22:04 sscotth