Huge Array filter performance (v6)

Revision 6 of this benchmark created on


Setup

var existingValues = new Array(50).fill(null).map((_,i) => 60000+i)
var existing = new Set(existingValues)
var alpha = new Array(50000).fill(null).map((_,i) => i)

Test runner

Ready to run.

Testing in
TestOps/sec
Filter and has
var result = alpha.filter((i) => !existing.has(i))
ready
Loop and has
function filter()
{
    var match = []

    for (var i = 0; i < alpha.length; i++)
    {
        if ( !existing.has(alpha[i]) ) match.push(alpha[i])
    }

    return match
}

var result = filter();
ready
Foreach loop
function filter()
{
    var match = []

    alpha.forEach(item => {
        if ( !existing.has(item) ) match.push(item)
    })

    return match
}

var result = filter();
ready
Loop and find
function filter()
{
    var match = []

    for (var i = 0; i < alpha.length; i++)
    {
        if (existingValues.find(value => value === alpha[i]) === undefined) match.push(alpha[i])
    }

    return match
}

var result = filter();
ready
Filter and find
var result = alpha.filter((i) => existingValues.find( value => value === i) === undefined)
ready

Revisions

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