Filter

Benchmark created by Dustin Fadler on


Setup

function randomNumber(seed) {
    return Math.random() * seed;
  }
  
  var nums = [];
  
  for(var i = 0, len = 1000; i < len; i++) {
    nums.push(randomNumber(10))
  }
  
  function predicate(x) {
    return x > randomNumber(10);
  }
  
  function filter(p, l) {
    function _filter(p, [first, ...last]) {
      if(!first) return [];
      return [
        p(first) ? first : [],
        _filter(p, last)]
          .reduce((x, y) => x.concat(y), []);
    }
    return _filter(p, l);
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Native
nums.filter(predicate);
ready
Recursion
filter(predicate, nums);
ready

Revisions

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

  • Revision 1: published by Dustin Fadler on