Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Underscore clone vs Underscore pick
(version: 0)
Comparing performance of:
underscore clone vs underscore pick
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js'></script>
Script Preparation code:
var MyObject = [{dateOfBirth_dateOfBirth: "babyBoomers", headcount: 644},{dateOfBirth_dateOfBirth: "genX", headcount: 605},{dateOfBirth_dateOfBirth: "millennial", headcount: 805}]; var myCopy = [];
Tests:
underscore clone
_.each(MyObject, function(d) { myCopy.push(_.clone(d)); });
underscore pick
_.each(MyObject, function(d) { myCopy.push(_.pick(d,['dateOfBirth_dateOfBirth','headcount'])); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
underscore clone
underscore pick
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/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
underscore clone
1979909.6 Ops/sec
underscore pick
909520.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help you understand what's being tested in this benchmark. **Benchmark Overview** The benchmark is designed to compare the performance of two approaches: using `underscore.clone()` and using `underscore.pick()`. The test cases involve creating an array of objects (`MyObject`) and then pushing either cloned or picked versions of these objects into another array (`myCopy`). **Options Compared** There are two main options being compared: 1. **_underscore.clone(d)**: This approach creates a shallow copy of the entire object `d`. It copies all properties, including nested ones. 2. **_underscore.pick(d, ['dateOfBirth_dateOfBirth', 'headcount'])**: This approach selects only specific properties from the object `d` and returns an object with those selected properties. **Pros and Cons** * **Shallow Copy (Underscore Clone)**: + Pros: creates a new object that is identical to the original in terms of structure, which can be useful for preserving object references. + Cons: may not be suitable when dealing with large objects or performance-critical code, as it involves creating a new object with all properties. * **Selected Properties (Underscore Pick)**: + Pros: more efficient than shallow copying, as it only selects specific properties and returns an object with those properties. + Cons: may not preserve the structure of the original object if there are nested objects or arrays. **Library Used** The benchmark uses Underscore.js, a popular JavaScript utility library. Specifically, it relies on two functions: * `_.clone()`: creates a shallow copy of an object * `_.pick()`: returns an object with selected properties **Special JS Feature/Syntax** There is no special JavaScript feature or syntax being tested in this benchmark. The code only uses standard JavaScript constructs and Underscore.js functions. **Other Alternatives** If you were to rewrite these benchmarks using a different library or approach, some alternatives could be: * Using `Array.prototype.slice()` or `Array.prototype.map()` instead of _.clone() and _.pick() * Using a custom implementation for shallow copying and property selection * Using a different utility library that offers similar functionality (e.g., Lodash) It's worth noting that the benchmark is designed to test the performance of these two approaches, not the performance of the entire Underscore.js library.
Related benchmarks:
Unerscore.keys vs object.keys
Underscore vs Array functions
Underscore clone vs JSON Clone
underscore clone VS spread operator
Comments
Confirm delete:
Do you really want to delete benchmark?