_.without vs .filter

Benchmark created on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.6/underscore-min.js"></script>

Setup

const testArray = [];
for (let i = 0; i < 100000; i++) {
    if (i % 5 === 0) {
        testArray.push(`string-${i}`);
    } else if (i % 3 === 0) {
        testArray.push(null);
    } else if (i % 2 === 0) {
        testArray.push(i);
    } else {
        testArray.push(i % 7 === 0); // boolean
    }
}

const valuesToRemove = [
    50,
    'string-100',
    null,
    true,
    999999,
    'non-existent-string'
];

Test runner

Ready to run.

Testing in
TestOps/sec
_.without
_.without(testArray, ...valuesToRemove);
ready
.filter
testArray.filter(item => !valuesToRemove.includes(item));
ready

Revisions

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