Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash pick vs manual object descturct10
(version: 0)
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>
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, }, }), {}); }
Object desctruct
for(i=0; i<100; i++){ const n = Object.keys(images || {}) .reduce((obj, key) => ({ ...obj, [key]: { downloadUrl: images[key].downloadUrl, id: images[key].id, blurhash: images[key].data?.blurhash, }, }), {}); }
Optimization1
for(i=0; i<100; i++){ 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 dive into the world of JavaScript microbenchmarks on MeasureThat.net. The provided JSON represents a benchmark test case that compares three different approaches to extract data from an object: using Lodash, manual destructuring, and another optimization approach (Optimization1). **Benchmark Test Case Overview** The benchmark test case is designed to measure the execution time of three different functions: 1. `Lodash`: Using the `pick` function from the Lodash library to extract specific properties from the `images` object. 2. `Object desctruct`: Manual destructuring using the spread operator (`...`) to create a new object with extracted properties. 3. `Optimization1`: A custom optimization approach that uses a similar structure to manual destructuring but without the use of the spread operator. **Options Compared** The benchmark compares two main approaches: * Lodash's `pick` function, which is a popular utility library for JavaScript. * Manual destructuring using the spread operator (`...`), which is a built-in JavaScript feature that allows creating new objects by copying properties from an existing object. **Pros and Cons of Each Approach** 1. **Lodash's `pick` function**: * Pros: Easy to use, efficient, and widely adopted library. * Cons: Adds dependency on the Lodash library, which may not be desirable for small projects or those with performance constraints. 2. **Manual destructuring using the spread operator (`...`)**: * Pros: Lightweight, built-in feature, and doesn't add external dependencies. * Cons: Can be verbose, less readable than other approaches, and may have performance implications due to the number of assignments. **Other Considerations** The benchmark also considers the **DevicePlatform** (Desktop vs. Mobile) and **OperatingSystem** (Mac OS X 10.15.7), which may affect execution times due to hardware and software differences. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks like string manipulation, array manipulation, and object manipulation. The `pick` function is used in the benchmark to extract specific properties from the `images` object. In summary, this benchmark test case compares three approaches to extract data from an object: using Lodash's `pick` function, manual destructuring using the spread operator (`...`), and another optimization approach (Optimization1). The results provide insight into the performance differences between these approaches on a specific dataset. **Alternatives** Other alternatives for this benchmark test case could include: * Using a different utility library, such as Underscore.js or Moment.js. * Implementing manual destructuring using a custom function instead of the spread operator (`...`). * Adding additional optimization techniques, like memoization or caching. * Testing on different datasets or platforms to compare performance differences. Feel free to ask me any further questions!
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?