Array filter performance (v4)

Revision 4 of this benchmark created on


Setup

var alpha = [];
    for (var i = 0; i <= 10000; i++) {
      alpha.push(i);
    }
    
    
    var testElement = function(i) {
        return i > 3;
        }

Test runner

Ready to run.

Testing in
TestOps/sec
Filter
var result = alpha.filter(testElement);
ready
Loop
function filter(a) {
  var match = []

  for (var i = 0; i < a.length; i++) {
    if (testElement(a[i])) match.push(a[i])
  }

  return match
}

var result = filter(alpha);
ready
bla
function filter(a) {
  b=a.slice(0);
  for (var i = a.length-1; i >= 0; i--) {
    if (!testElement(a[i])) b.splice(i,1)
  }
  return b
}

var result = filter(alpha);
ready
blubb
var result = alpha.filter(testElement);
ready

Revisions

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