ArrayFilter

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
phpjs array filter
function array_filter(arr, func) {
  var retObj = {},
    k;

  func = func || function(v) {
    return v;
  };

  if (Object.prototype.toString.call(arr) === '[object Array]') {
    retObj = [];
  }

  for (k in arr) {
    if (func(arr[k])) {
      retObj[k] = arr[k];
    }
  }

  return retObj;
}
function isBigEnough(value) {
  return value >= 10;
}
var filtered = array_filter([12, 5, 8, 130, 44], isBigEnough);
ready
Array.filter
function isBigEnough(value) {
  return value >= 10;
}
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
ready

Revisions

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