reduce vs filter+map

JavaScript performance comparison

Test case created by zaguiini

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const myArray = new Array(250).fill(1).map(_ => Math.round(Math.random() * 100))

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
filter + map
myArray.filter(i => i < 50).map(i => i * 5)
pending…
reduce
myArray.reduce((curr, next) => {
    if(next < 50) {
      curr.push(next * 5)
    }
    
    return curr
}, [])
pending…

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments