Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash pick vs manual object descturct6
(version: 7)
Comparing performance of:
Lodash vs Object desctruct vs Optimization1
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>
Tests:
Lodash
const 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 } } } const n = Object.keys(images || {}) .reduce((obj, key) => ({ ...obj, [key]: { ..._.pick(images[key], ['downloadUrl', 'id']), blurhash: images[key].data?.blurhash, }, }), {});
Object desctruct
const 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 } } } const n = Object.keys(images || {}) .reduce((obj, key) => ({ ...obj, [key]: { downloadUrl: images[key].downloadUrl, id: images[key].id, blurhash: images[key].data?.blurhash, }, }), {});
Optimization1
const 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 } } } const n = Object.keys(images || {}) .reduce((obj, key) => { obj[key] = { downloadUrl: images[key].downloadUrl, id: images[key].id, blurhash: images[key].data?.blurhash, } return obj; }, {});
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash
Object desctruct
Optimization1
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 test case and explain what's being tested. **Benchmark Definition** The benchmark test case is comparing three different approaches to extract data from an object: 1. `Lodash pick` 2. `Object desctruct` (note: this is likely a typo, and it should be " destructuring") 3. `Optimization1` Each approach has its own script preparation code. **Options being compared** The three options are being compared in terms of their execution speed. The benchmark measures the number of executions per second for each option. **Pros and Cons of each approach:** 1. **Lodash pick**: Lodash is a popular JavaScript utility library that provides a function called `pick` to extract specific properties from an object. This approach uses the `_.pick` function from Lodash to extract only the required properties. Pros: concise, efficient, and easy to use. Cons: depends on the presence of the Lodash library. 2. **Object desctruct**: This approach uses destructuring assignment to extract the required properties from the object. Pros: lightweight, fast, and easy to understand. Cons: may not be as readable or maintainable as other approaches. 3. **Optimization1**: The code for this option is similar to the `Lodash pick` approach but without using Lodash. Instead, it uses a loop to iterate over the object properties and extract only the required ones. Pros: fast, lightweight, and doesn't depend on any libraries. Cons: more verbose than other approaches. **Latest benchmark result** The latest benchmark result shows that: * `Optimization1` is the fastest option, executing approximately 170 executions per second. * `Object desctruct` comes in second, with around 532 executions per second. * `Lodash pick` takes the third spot, executing about 144 executions per second. Overall, the benchmark suggests that `Optimization1` is the most efficient approach, followed closely by `Object desctruct`.
Related benchmarks:
lodash.keys [4.17.11] vs Object.keys
trim loadsh vs native trim
lodash.size vs lodash.keys
isEmpty vs. vanilla
lodash noop vs new function vs optional chaining
Comments
Confirm delete:
Do you really want to delete benchmark?