Huge Array filter performance (v11)

Revision 11 of this benchmark created on


Setup

var existingValues = new Array(5).fill(null).map((_,i) => 2500+i)
var existing = new Set(existingValues)
var existingObject = Object.fromEntries(existingValues.map(v => [v, true]))
var alpha = new Array(5000).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 plain object
function filter()
{
    var match = []

    for (const i of alpha)
    {
        if (existingObject[i] === undefined) match.push(i)
    }

    return match
}

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

    for (const i of alpha)
    {
        if (!existingValues.some(value => value === i)) match.push(i)
    }

    return match
}

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

    for (const i of alpha)
    {
        if (existingValues.find(value => value === i)===undefined) match.push(i)
    }

    return match
}

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

    for (const value of alpha)
    {
        if (!existing.has(value)) match.push(value)
    }

    return match
}

var result = filter();
ready

Revisions

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