Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash pick vs manual object descturct11
(version: 0)
Comparing performance of:
Lodash vs Object desctruct vs Optimization1 vs Optimization2
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; }, {}); }
Optimization2
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 (4)
Previous results
Fork
Test case name
Result
Lodash
Object desctruct
Optimization1
Optimization2
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! **Benchmark Overview** The MeasureThat.net website allows users to create and run JavaScript microbenchmarks. The provided benchmark, "Lodash pick vs manual object desctruct11", tests the performance of two approaches: using Lodash's `pick` function and a manual object destructuring approach. **What is being tested?** The benchmark compares the performance of creating an object from scratch by: 1. Using Lodash's `pick` function to extract specific properties from the `images` object. 2. Manual object destructuring, where the object keys are iterated over and each key-value pair is added to a new object. **Options Compared** Two options are being compared: 1. **Lodash's `pick` function**: This function takes an object and an array of property names as arguments and returns a new object with only the specified properties. 2. **Manual Object Destructuring**: This approach involves iterating over the keys of the `images` object, creating a new object with each key-value pair. **Pros and Cons** 1. **Lodash's `pick` function**: * Pros: Convenient, easy to use, and performant (thanks to its optimized implementation). * Cons: Requires an additional library dependency (Lodash), and might be overkill for small objects. 2. **Manual Object Destructuring**: * Pros: Lightweight, no additional dependencies required, and can be easily modified to fit specific needs. * Cons: More verbose, error-prone, and requires manual key-value pair creation. **Other Considerations** When choosing between these approaches, consider the trade-off between convenience, performance, and complexity. If you need a simple, performant solution for small objects, Lodash's `pick` function might be the better choice. However, if you're working with large datasets or need more control over the object creation process, manual object destructuring could be a better fit. **Libraries Used** The benchmark uses Lodash version 4.17.5. Lodash is a popular JavaScript utility library that provides various functions for tasks such as array manipulation, string formatting, and object transformation. **Special JS Feature/ Syntax** There doesn't seem to be any special JavaScript features or syntax used in this benchmark. However, if you're interested in exploring more advanced features like ES6+ syntax, let me know! **Other Alternatives** If you need similar benchmarks for other scenarios, here are some alternatives: * For object creation performance: `Object.assign()` vs `Array.prototype.concat()` * For array manipulation performance: `Lodash's `map()` and `filter()` functions` vs `Array.prototype.map()` and `Array.prototype.filter()` * For string formatting performance: `String.prototype.format()` vs `Template literals` Feel free to ask me about any of these alternatives, and I'll do my best to provide more information!
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?