Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Filtering out empty rows from a 2D Array
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Double negation (!!row.length)
152298.1 Ops/sec
Comparison (row.length > 0)
151366.2 Ops/sec
Double negation (!!row)
115756.5 Ops/sec
Boolean constructor
124921.1 Ops/sec
Script Preparation code:
// Array with alternating empty and non-empty arrays const arraySize = 1000; var testArray = new Array(arraySize) .fill(null) .map((_, i) => i % 2 === 0 // Make the values alternate between 0-2 ? new Array(i).fill(0).map((_, j) => j % 2) : []); function doubleNegateLength({ length }) { return !!length; } function lengthGreaterThanZero({ length }) { return length > 0; } function doubleNegate(value) { return !!value; } var booleanConstructor = Boolean;
Tests:
Double negation (!!row.length)
testArray.filter(doubleNegateLength);
Comparison (row.length > 0)
testArray.filter(lengthGreaterThanZero);
Double negation (!!row)
testArray.filter(doubleNegate);
Boolean constructor
testArray.filter(booleanConstructor);