Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
filter vs delete from object
(version: 0)
Comparing performance of:
using filter vs using check before filter vs checking amount and if
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var participants = { "1234": { "hidden": true, "name": "flol" }, "5678": { "hidden": true, "name": "flol" }, "9101": { "hidden": true, "name": "flol" }, "1121": { "hidden": true, "name": "flol" }, "3141": { "hidden": true, "name": "flol" }, "5161": { "hidden": true, "name": "flol" }, "7181": { "hidden": true, "name": "flol" }, "9202": { "hidden": true, "name": "flol" }, "1223": { "hidden": true, "name": "flol" }, "3243": { "hidden": true, "name": "flol" }, "1": { "hidden": true, "name": "flol" }, "2": { "hidden": true, "name": "flol" }, "3": { "hidden": true, "name": "flol" }, "4": { "hidden": true, "name": "flol" }, "5": { "hidden": true, "name": "flol" }, "6": { "hidden": true, "name": "flol" }, "7": { "hidden": true, "name": "flol" }, "8": { "hidden": true, "name": "flol" }, "9": { "hidden": true, "name": "flol" }, "10": { "hidden": true, "name": "flol" }, "11": { "hidden": true, "name": "flol" }, "12": { "hidden": true, "name": "flol" }, "13": { "hidden": true, "name": "flol" }, "14": { "hidden": true, "name": "flol" }, "15": { "hidden": true, "name": "flol" }, "16": { "hidden": true, "name": "flol" }, "17": { "hidden": true, "name": "flol" }, "18": { "hidden": true, "name": "flol" }, "19": { "hidden": true, "name": "flol" }, "20": { "hidden": true, "name": "flol" }, "21": { "hidden": true, "name": "flol" }, "22": { "hidden": true, "name": "flol" }, "23": { "hidden": true, "name": "flol" }, "24": { "hidden": true, "name": "flol" }, "25": { "hidden": true, "name": "flol" }, "26": { "hidden": true, "name": "flol" }, "27": { "hidden": true, "name": "flol" }, "28": { "hidden": true, "name": "flol" }, "29": { "hidden": true, "name": "flol" }, "30": { "hidden": true, "name": "flol" }, "31": { "hidden": true, "name": "flol" }, "32": { "hidden": true, "name": "flol" }, "33": { "hidden": true, "name": "flol" }, "34": { "hidden": true, "name": "flol" }, "35": { "hidden": true, "name": "flol" }, "36": { "hidden": true, "name": "flol" }, "37": { "hidden": true, "name": "flol" }, "38": { "hidden": true, "name": "flol" }, "39": { "hidden": true, "name": "flol" }, "40": { "hidden": true, "name": "flol" }, "41": { "hidden": true, "name": "flol" }, "42": { "hidden": true, "name": "flol" }, "43": { "hidden": true, "name": "flol" }, "44": { "hidden": true, "name": "flol" }, "45": { "hidden": true, "name": "flol" }, "46": { "hidden": true, "name": "flol" }, "47": { "hidden": true, "name": "flol" }, "48": { "hidden": true, "name": "flol" }, "49": { "hidden": true, "name": "flol" }, "50": { "hidden": true, "name": "flol" }, "51": { "hidden": true, "name": "flol" }, "52": { "hidden": true, "name": "flol" }, "53": { "hidden": true, "name": "flol" }, "54": { "hidden": true, "name": "flol" }, "55": { "hidden": true, "name": "flol" }, "56": { "hidden": true, "name": "flol" }, }; var currentID = "51"; var noCurrentID = 200;
Tests:
using filter
const allParticipants = Object.keys(participants).filter((id) => id !== currentID); const allParticipants2 = Object.keys(participants).filter((id) => id !== noCurrentID);
using check before filter
if (participants[currentID]) { const allParticipants = Object.keys(participants).filter((id) => id !== currentID); } if (participants[noCurrentID]) { const allParticipants = Object.keys(participants).filter((id) => id !== noCurrentID); }
checking amount and if
const coef = participants[currentID] ? 1 : 0; const amountOfParticipants = Object.keys(participants).length - coef; if (amountOfParticipants === 1) {} else {} const coef2 = participants[noCurrentID] ? 1 : 0; const amountOfParticipants2 = Object.keys(participants).length - coef2; if (amountOfParticipants2 === 1) {} else {}
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
using filter
using check before filter
checking amount and if
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 OPR/109.0.0.0
Browser/OS:
Opera 109 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
using filter
116060.4 Ops/sec
using check before filter
223954.2 Ops/sec
checking amount and if
338498.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
A complex benchmarking scenario! It appears that we have a JSON object with two arrays: `participants` and some additional metadata. The `participants` array has multiple entries, each with an ID and a corresponding value. We're interested in a specific entry where the ID is "51". We also have three individual test cases: 1. **"using filter"`**: This test case uses the `filter()` method to exclude the current ID from all participants. 2. **"using check before filter"`**: This test case checks if the current ID or another ID (200) exists in the `participants` array, and then filters out those IDs using the same approach as above. 3. **"checking amount and if"`**: This test case uses conditional statements to determine if there is only one participant left after filtering. The latest benchmark results show three different browsers/clients running these tests at varying rates: 1. **"checking amount and if"`** ( Opera 109, Windows, Desktop): 338498.125 executions per second 2. **"using check before filter"`** (Opera 109, Windows, Desktop): 223954.234375 executions per second 3. **"using filter"`** (Opera 109, Windows, Desktop): 116060.4453125 executions per second What would you like to know or achieve with this benchmarking data?
Related benchmarks:
Native filter vs lodash find
splice + spread vs filter to remove one item at given index
spread + splice vs filter to remove one item at given index
spread + splice vs slice + spread vs filter to remove one item at given index
slice + spread vs filter vs spread copy + splice to remove one item at given index
Comments
Confirm delete:
Do you really want to delete benchmark?