Array filter performance

Benchmark created by Matt Hinchliffe on


Setup

var alpha = [1, 2, 3, 4, 5, 6];

Test runner

Ready to run.

Testing in
TestOps/sec
Filter
var result = alpha.filter(function(i)
{
    return i > 3;
});
ready
Loop
function filter(a)
{
    var match = []

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

    return match
}

var result = filter(alpha);
ready

Revisions

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