Internally imperative vs pure partition

JavaScript performance comparison

Test case created by davidkpiano

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const array = [...Array(1000).keys()];
  
  const purePartition = (predicate, items) => items.reduce(([passes, fails], item) => predicate(item) ? [[...passes, item], fails] : [passes, [...fails, item]], [[], []]);
  
  function internallyImperativePartition(predicate, items) {
    return items
      .reduce((acc, item) => (acc[predicate(item) ? 0 : 1].push(item), acc), [[],[]]);
  }

};
</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
Internally imperative
internallyImperativePartition(x => x % 2 === 0, array)
pending…
Pure
purePartition(x => x % 2 === 0, array)
pending…

Compare results of other browsers

Revisions

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

0 Comments