Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
compare for loop vs array.filter vs array.filter with array.includes
compare for loop vs array.filter
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0
Browser:
Firefox 115
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
array.filter
13527018.0 Ops/sec
for loop
4199690.5 Ops/sec
array.filter with array.includes
6799107.5 Ops/sec
Script Preparation code:
boxType = 'STORAGE'; inspectionPendingBoxCount = 0; boxList = [ { 'id': 1, 'boxCode': 'b1', 'purpose': 'STORAGE', 'isInspectionReq': true, 'status': 'INSPECTION_IN_PROGRESS' }, { 'id': 2, 'boxCode': 'b2', 'purpose': 'STORAGE', 'isInspectionReq': true, 'status': 'RECEIVED' }, { 'id': 3, 'boxCode': 'b3', 'purpose': 'CROSSDOCK', 'isInspectionReq': false, 'status': 'INSPECTION_IN_PROGRESS' }, { 'id': 4, 'boxCode': 'b4', 'purpose': 'STORAGE', 'isInspectionReq': true, 'status': 'INSPECTION_DONE' }, { 'id': 5, 'boxCode': 'b5', 'purpose': 'STORAGE', 'isInspectionReq': false, 'status': 'INSPECTION_IN_PROGRESS' } ];
Tests:
array.filter
inspectionPendingBoxCount = boxList?.filter(box=> boxType == box?.purpose && box?.isInspectionReq && (box?.status=='INSPECTION_IN_PROGRESS' || box?.status=='RECEIVED'))?.length;
for loop
for(let box of boxList){ if(boxType == box?.purpose && box?.isInspectionReq && (box?.status=='INSPECTION_IN_PROGRESS' || box?.status=='RECEIVED')) inspectionPendingBoxCount+=1; }
array.filter with array.includes
inspectionPendingBoxCount = boxList?.filter(box=> boxType == box?.purpose && box?.isInspectionReq && ['INSPECTION_IN_PROGRESS', 'RECEIVED'].includes?.(box?.status))?.length;