Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test 2
(version: 0)
Comparing performance of:
spread vs shallow copy
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var route = { "appConfigId": "8f7cd9d8534d0d10a86bddeeff7b12bc", "experienceId": "bb508d10530d0d10a86bddeeff7b12e9", "experienceName": "ACE App Builder", "pageProperties": { "chrome_header": "{\"privatePage\":{\"notificationsEnabled\":true,\"searchEnabled\":false,\"userPrefsEnabled\":true,\"contextualConfigurationItems\":{\"enabled\":false},\"globalTools\":{\"collapsingMenuId\":0,\"primaryItems\":[{\"label\":\"UserMenu\",\"icon\":\"user\",\"type\":\"menu\",\"primaryDisplay\":\"icon\",\"value\":{\"children\":[{\"label\":\"Logout\",\"position\":500,\"type\":\"navigation\",\"value\":{\"value\":{\"href\":\"/logout.do\"},\"type\":\"external\"}}]}}]}},\"publicPage\":{\"actionButtons\":[],\"notificationsEnabled\":false,\"searchEnabled\":false,\"userPrefsEnabled\":false,\"menuEnabled\":false}}", "ace_application_id": "1a418990530d0d10a86bddeeff7b1200", "chrome_footer": "{\"public_page\":{\"enable_footer_topbar\":false,\"footer_topbar_options\":{},\"enable_footer_bar\":false,\"footer_bar_options\":{}}}" }, "urlPath": "now/ace-app-builder" } function shallowCopy(...objs) { const res = Object.create(null); for (const obj of objs) { for (const key in obj) { res[key] = obj[key]; } } res.hasOwnProperty = (prop) => { return prop in res; } return res; }
Tests:
spread
var res = { ...route, viewportElementId: 'uxf-viewport-screen', reinitialize: true }
shallow copy
var res = shallowCopy(route, { viewportElementId: 'uxf-viewport-screen', reinitialize: true })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
spread
shallow copy
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll explain the benchmark and its options. **Benchmark Definition** The provided JSON represents two individual test cases for measuring JavaScript performance. The test cases are designed to compare two approaches: spreading an object (using the `...` syntax) versus shallow copying an object using a custom function (`shallowCopy`). **Options Compared** There are two main options being compared: 1. **Spreading**: This involves using the `...` syntax to spread an object's properties into a new object, effectively creating a deep copy of the original object. 2. **Shallow Copy**: This involves using a custom function (`shallowCopy`) to create a shallow copy of an object, which only copies the top-level properties without recursively copying nested objects. **Pros and Cons** **Spreading:** Pros: * More concise and expressive syntax * Can be faster since it doesn't require explicit looping or recursion Cons: * May not work correctly for objects with circular references (since JavaScript's `...` syntax only creates a shallow copy) * May have performance implications due to the overhead of creating a new object **Shallow Copy:** Pros: * Ensures that all properties, including nested objects, are copied correctly * Can be more predictable and maintainable for complex object hierarchies Cons: * Requires explicit looping or recursion to create a copy, which can be slower than spreading * May require additional memory allocation since it creates a new object **Other Considerations** * The `shallowCopy` function is defined in the Benchmark Definition code snippet. This function takes two arguments: the object to copy and an options object with properties that affect the shallow copy process. * The `reinitialize` property is used to control whether the copied object should be reinitialized after copying. **Alternatives** Other approaches could have been taken, such as: * Using a library like Lodash's `cloneDeep` function to create a deep copy of an object * Using a library like Immer or Redux-Immutable to manage state changes and create a shallow copy * Implementing a custom recursive copy function without using the `...` syntax However, these alternatives might not be as concise or expressive as spreading, while still providing a robust way to compare performance.
Related benchmarks:
lo vs native
CloneDeep BenchMarks
filter-map-reduce
mybencmark115000
Comments
Confirm delete:
Do you really want to delete benchmark?