Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Creating a partial object: destructuring vs. property picking
(version: 0)
Comparing performance of:
Object destructuring vs Property picking
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
Object destructuring
const obj = { a:1, b:1, c:1, d:1, e:1, f:1, g:1, h:1, i:1, } const {a, d, i} = obj; const n = {a, d, i};
Property picking
const obj = { a:1, b:1, c:1, d:1, e:1, f:1, g:1, h:1, i:1, } const n = {a: obj.a, d: obj.d, i: obj.i};
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object destructuring
Property picking
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object destructuring
230114640.0 Ops/sec
Property picking
204251888.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided JSON and explain what's being tested, the options compared, their pros and cons, and other considerations. **Benchmark Definition** The benchmark is designed to compare two approaches for creating a partial object: 1. **Object Destructuring**: Using the syntax `const {a, d, i} = obj;`, where an object literal `{...}` is used to create a new object with only the specified properties. 2. **Property Picking**: Using the syntax `const n = {a: obj.a, d: obj.d, i: obj.i};`, where each property value is explicitly assigned using dot notation (`obj.property`). **Options Compared** The benchmark compares the performance of these two approaches: * **Object Destructuring**: Creating a new object with only the desired properties using destructuring syntax. * **Property Picking**: Assigning individual property values to create a partial object. **Pros and Cons** **Object Destructuring:** Pros: * More concise and readable code * Less boilerplate code Cons: * May not be as efficient in older browsers or environments with limited support for modern JavaScript features * Can lead to unexpected behavior if the order of properties matters (e.g., `const {a, b} = obj; const c = a + b`) **Property Picking:** Pros: * More explicit and controllable code * May be more efficient in older browsers or environments Cons: * Longer and less concise code * Requires more manual effort to specify each property value **Other Considerations** * Both approaches create a new object with only the desired properties, so they should have similar performance characteristics for most modern JavaScript engines. * The choice between destructuring and property picking ultimately depends on personal preference, coding style, and specific use case requirements. **Library Usage** There is no library explicitly mentioned in the benchmark definition. However, it's worth noting that some JavaScript engines may optimize or provide additional features for object creation and manipulation. **Special JS Features/Syntax** None are mentioned specifically, but keep in mind that modern JavaScript engines often support advanced features like destructuring, arrow functions, and template literals. **Alternatives** Other alternatives to these approaches include: * Using the `Object.assign()` method to create a partial object. * Utilizing a library or framework-specific implementation for creating objects (e.g., React's `Partial` type). * Employing other object creation techniques, such as using the spread operator (`{...obj}`) or the `Object.create()` method. However, the original benchmark definition primarily focuses on comparing object destructuring and property picking, making these alternatives less relevant.
Related benchmarks:
Delete vs destructure for objects
Delete vs destructure for cloned objects
Delete vs destructure for objects 2
Delete vs destructure for objects v2 2
Delete vs destructure for objects - guigo2
Comments
Confirm delete:
Do you really want to delete benchmark?