Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Omit performance
(version: 0)
Comparing performance of:
Omit Inline vs Omit For vs Omit ForOf vs Omit Entries vs Omit Reduce
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var arr = []; for (let i = 0; i < 100000; i++) { arr.push({ value: i, textValue: 'text-' + i + '' + Math.random(), createdAt: Math.random(), createdBy: Math.ceil(Math.random() + 10), updatedAt: i, updatedBy: Math.ceil(Math.random() + 10), }) } var omitInline = (obj, keys) => { const newObj = { ...obj }; if (keys.length > 4) { return keys.reduce((acc, key) => { delete acc[key]; return acc; }, newObj); } delete newObj[keys[0]]; if (keys.length === 1) return newObj; delete newObj[keys[1]]; if (keys.length === 2) return newObj; delete newObj[keys[2]]; if (keys.length === 3) return newObj; delete newObj[keys[3]]; return newObj; } var omitReduce = (obj, keys) => { const newObj = { ...obj }; if (keys.length > 3) { return keys.reduce((acc, key) => { delete acc[key]; return acc; }, newObj); } delete newObj[keys[0]]; if (keys.length === 1) return newObj; delete newObj[keys[1]]; if (keys.length === 2) return newObj; delete newObj[keys[2]]; return newObj; } var omitFor = (obj, keys) => { const newObj = { ...obj }; if (keys.length > 3) { for (let i = 0; i <= keys.length; i++) { delete newObj[keys[i]]; } return newObj } delete newObj[keys[0]]; if (keys.length === 1) return newObj; delete newObj[keys[1]]; if (keys.length === 2) return newObj; delete newObj[keys[2]]; return newObj; } var omitForOf = (obj, keys) => { const newObj = { ...obj }; if (keys.length > 3) { for (const key of keys) { delete newObj[key]; } return newObj } delete newObj[keys[0]]; if (keys.length === 1) return newObj; delete newObj[keys[1]]; if (keys.length === 2) return newObj; delete newObj[keys[2]]; return newObj; } var omitEntries = (obj, keys) => { const newObj = { ...obj }; if (keys.length > 3) { return Object.fromEntries(Object.entries(obj).filter(entry => !keys.includes(entry[0]))) } delete newObj[keys[0]]; if (keys.length === 1) return newObj; delete newObj[keys[1]]; if (keys.length === 2) return newObj; delete newObj[keys[2]]; return newObj; }
Tests:
Omit Inline
return arr.map(item => omitInline(item, ['createdAt', 'createdBy', 'updatedAt', 'updatedBy']))
Omit For
return arr.map(item => omitFor(item, ['createdAt', 'createdBy', 'updatedAt', 'updatedBy']))
Omit ForOf
return arr.map(item => omitForOf(item, ['createdAt', 'createdBy', 'updatedAt', 'updatedBy']))
Omit Entries
return arr.map(item => omitEntries(item, ['createdAt', 'createdBy', 'updatedAt', 'updatedBy']))
Omit Reduce
return arr.map(item => omitReduce(item, ['createdAt', 'createdBy', 'updatedAt', 'updatedBy']))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Omit Inline
Omit For
Omit ForOf
Omit Entries
Omit Reduce
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Omit Inline
38.4 Ops/sec
Omit For
37.4 Ops/sec
Omit ForOf
38.1 Ops/sec
Omit Entries
17.7 Ops/sec
Omit Reduce
36.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Definition** The benchmark is designed to measure the performance of different approaches for omitting specific properties from objects in JavaScript. The input data is an array of objects, `arr`, which contains 100,000 items with various properties (e.g., `value`, `textValue`, `createdAt`, `createdBy`, etc.). **Individual Test Cases** There are four test cases: 1. **Omit Inline**: Uses the `omitInline` function to remove the specified properties from each object in the array. 2. **Omit For**: Uses the `omitFor` function to achieve the same result as `omitInline`. 3. **Omit ForOf**: Uses the `omitForOf` function, which is similar to `omitInline`, but with a different implementation. 4. **Omit Reduce**: Uses the `omitReduce` function, which applies a reduce operation to the array of objects. **Latest Benchmark Result** The benchmark results show the performance metrics for each test case, including: * `RawUAString`: The user agent string (e.g., "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36") * `Browser`: The browser name and version (Chrome 120) * `DevicePlatform`: The device platform (Desktop) * `OperatingSystem`: The operating system (Mac OS X 10.15.7) * `ExecutionsPerSecond`: The number of executions per second for each test case **Interpretation** The benchmark results show that: * **Omit Inline** and **Omit ForOf** have similar performance profiles, with Chrome 120 executing approximately 38-40 times per second. * **Omit For** has slightly worse performance compared to the other two approaches (around 36-37 times per second). * **Omit Reduce** has the worst performance among all test cases (around 17 times per second). In summary, the benchmark results suggest that `omitInline` and `omitForOf` are the most efficient approaches for omitting properties from objects in JavaScript, while `omitReduce` may not be suitable for large datasets due to its performance characteristics.
Related benchmarks:
Large Map vs Object 2
Object key access vs array index access 1000000
Map vs Object (real-world) Performance (better) 2
immutable object/set/array
Comments
Confirm delete:
Do you really want to delete benchmark?