Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Object.values vs filter(Boolean)
Filtering out undefined values
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Browser:
Chrome 122
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Object.values
13781.0 Ops/sec
filter(Boolean)
13884.4 Ops/sec
Script Preparation code:
var nbspCharacter = '\u00A0'; var GROUPS = [ [ -Infinity, 0, `< 1${nbspCharacter}min` ], [ 1, 4, `1 - 4${nbspCharacter}min` ], [ 5, 14, `5 - 14${nbspCharacter}min` ], [ 15, 29, `15 - 29${nbspCharacter}min` ], [ 30, 59, `30 - 59${nbspCharacter}min` ], [ 60, Infinity, `60${nbspCharacter}min <` ], ]; var entries = []; for(i=0; i<100; i++){ entries.push({minutes: Math.floor(Math.random() * 2), count: Math.floor(Math.random() * 10)}); entries.push({minutes: 30 + Math.floor((Math.random() * 60)), count: Math.floor(Math.random() * 10)}); } var reducer = (acc, entry) => { const { minutes, count } = entry; const groupId = GROUPS.findIndex(([ min, max ]) => { return minutes >= min && minutes <= max; }); acc[groupId] = { x: GROUPS[groupId][2] || (GROUPS[groupId].map((v) => `${v}${nbspCharacter}min`).join(' - ')), count: parseInt((acc?.[groupId]?.count ?? 0), 10) + parseInt(count, 10), }; acc[groupId].y = acc[groupId].count; return acc; }
Tests:
Object.values
Object.values(entries.reduce(reducer, {}))
filter(Boolean)
entries.reduce(reducer, []).filter(Boolean);