Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash pick vs manual object descturct12
(version: 0)
Comparing performance of:
Lodash vs Optimization
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:
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, }, }), {}); }
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"]), } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash
Optimization
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 benchmark and explain what is being tested. **Overview** The benchmark compares two approaches to extract specific properties from an object in JavaScript: using Lodash's `pick` function and writing a manual implementation. **Lodash `pick` function** The `pick` function is part of the popular utility library Lodash. It takes two arguments: 1. An object to extract properties from 2. An array of property names to extract In this benchmark, the `pick` function is used to extract specific properties (`downloadUrl`, `id`, and `blurhash`) from the `images` object. **Manual implementation** The manual implementation uses a similar approach to extract properties, but without using Lodash's `pick` function. It defines a named function `pick` that takes an image object as input and returns a new object with only the desired properties. Both implementations use the same syntax to access nested properties (e.g., `images[key].data.blurhash`) and produce the same output. **Pros and Cons** **Lodash `pick` function:** Pros: * Faster execution time, likely due to Lodash's optimized implementation * Less code to write and maintain Cons: * Adds an external dependency (Lodash) to the benchmark * May not be suitable for all use cases where a custom implementation is required **Manual implementation:** Pros: * Does not rely on an external library, making it more portable * Can be customized to fit specific requirements Cons: * Slower execution time, likely due to the overhead of defining and calling a function * More code to write and maintain **Other considerations** * The benchmark uses a simple object structure for the `images` data, which may not reflect real-world use cases. * The manual implementation assumes that all images have the desired properties (`downloadUrl`, `id`, and `blurhash`). In reality, some images might be missing these properties. **Alternatives** If you're looking for alternative implementations or alternatives to Lodash, consider: * Using a lightweight object cloning library like `lodash.clone` or `immer` * Implementing a custom property extraction function using a library like `es5-objects` or `object-assign` * Avoiding the use of external libraries altogether and implementing the logic in-house
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?