Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash pick vs manual object descturct13
(version: 0)
Comparing performance of:
Optimization vs Lodash
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var images = { "1280x1840_480": { "downloadUrl": "https://static.manta.net/2022-07-20/C3/C3PgwSGN2kE1BQQh.jpg", "data": { "blurhash": "UjIO2.IoyCRP~pjFxuW=%Mxue.xu%MWUNGs:", "height": 690, "width": 480 } }, "1280x1840_720": { "downloadUrl": "https://static.manta.net/2022-07-20/Lr/LrbiRJxUnwT5Trs5.jpg", "data": { "blurhash": "UjIO2-IoyCRP~pjF%2W=%MxujFxu%MaxNGs:", "height": 1035, "width": 720 } } }
Tests:
Optimization
const pick = (image) => ({ downloadUrl: image.downloadUrl, id: image.id, blurhash: image.data?.blurhash, }); for(i=0; i<100; i++){ const n = { "1280x1840_480": pick(images["1280x1840_480"]), "1280x1840_720": pick(images["1280x1840_720"]), } }
Lodash
for(i=0; i<100; i++){ const n = Object.keys(images || {}) .reduce((obj, key) => ({ ...obj, [key]: { ..._.pick(images[key], ['downloadUrl', 'id']), blurhash: images[key].data?.blurhash, }, }), {}); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Optimization
Lodash
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):
Let's break down the provided benchmark and explain what is being tested, compared, and discussed. **Benchmark Context** The benchmark measures the performance of two approaches to extract specific properties from an object: manual object destructuring versus using Lodash's `pick` function. The test case uses a predefined JavaScript object (`images`) that contains multiple nested objects with varying levels of complexity. **Options Compared** Two options are being compared: 1. **Manual Object Destructuring**: This approach requires the developer to manually extract specific properties from each object in the `images` array using the syntax: `{ key: value }`. This method is likely to be slower due to the overhead of parsing and manipulating the JavaScript code. 2. **Lodash's `pick` Function**: Lodash is a popular utility library for functional programming in JavaScript. The `pick` function takes an object, a list of property names, and returns a new object with only those properties. This method is likely to be faster since it leverages the optimized performance of the Lodash library. **Pros and Cons** * **Manual Object Destructuring**: + Pros: No external dependencies (i.e., no additional library to load), simple syntax. + Cons: Can be slower due to parsing and manipulation overhead, prone to errors if not done correctly. * **Lodash's `pick` Function**: + Pros: Optimized performance, fewer lines of code, less error-prone. + Cons: Requires an external dependency (the Lodash library), may have a slight performance overhead. **Library Used - Lodash** Lodash is a popular utility library for functional programming in JavaScript. Its `pick` function is designed to extract specific properties from objects efficiently and safely. The `pick` function takes three arguments: * Object: the object to extract properties from. * Paths: an array of property paths (e.g., `"downloadUrl"`, `"id"`). * ByValue: a boolean indicating whether to return the value or a copy. In this benchmark, Lodash's `pick` function is used to simplify the process of extracting specific properties from each object in the `images` array. **Special JS Features/Syntax** This benchmark does not explicitly use any special JavaScript features or syntax. However, it relies on modern JavaScript syntax and features like object destructuring, arrow functions, and template literals (e.g., `${...}`). **Alternatives** If you're looking for alternatives to Lodash's `pick` function, you could consider: * Using the spread operator (`{ ... }`) to create a new object with only the desired properties. * Utilizing libraries like `lodash-deep-extend` or `obj-assign` that provide similar functionality. Keep in mind that these alternatives may have different performance characteristics and trade-offs compared to Lodash's `pick` function.
Related benchmarks:
trim loadsh vs native trim
trim vs lodash/fp
lodash.size vs lodash.keys
isEmpty vs. vanilla
Lodash omit VS pick
Comments
Confirm delete:
Do you really want to delete benchmark?