Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash map
(version: 1)
Comparing performance of:
Arrow Function filter vs Prop vs Memoized
Created:
8 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.js"></script>
Script Preparation code:
var arr = []; for(let i=0; i < 100; i++){ arr.push({ object: { id: _.random(0, 5) } }); } var getProp = _.memoize(function(propString){ const props = propString.split('.'); return (val) => _.reduce(props, (val, prop) => prop in val ? val[prop] : undefined, val); });
Tests:
Arrow Function filter
_.map(arr, (i) => i.object.id);
Prop
_.map(arr, 'object.id')
Memoized
_.map(arr, getProp('object.id'))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Arrow Function filter
Prop
Memoized
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):
I'll break down the provided benchmark and its components. **Benchmark Overview** The benchmark measures the performance of the `_.map()` function from the Lodash library on an array of objects. The test creates an array with 100 objects, each containing an "id" property. It then defines a memoized getter function using `_memoize()` that takes a string representing the path to the desired property. **Options Compared** The benchmark compares three different approaches: 1. **Arrow Function Filter**: `_.map(arr, (i) => i.object.id)` * Pros: concise and readable code; arrow functions are often faster than traditional functions. * Cons: may not be as efficient due to function creation overhead. 2. **Prop Access**: `_.map(arr, 'object.id')` * Pros: straightforward and easy to read; Lodash's prop access is optimized for performance. * Cons: uses a string to represent the property path, which might lead to slower execution times. 3. **Memoized Getter**: `_.map(arr, getProp('object.id'))`, where `getProp` is a memoized getter function * Pros: can provide significant performance benefits due to caching; Lodash's memoization mechanism is optimized for efficiency. * Cons: requires defining the memoized getter function beforehand. **Lodash Library** The benchmark uses the Lodash library, which provides a set of utility functions for functional programming. In this case, `_.map()` and `_memoize()` are used to perform array transformations and create memoized getters, respectively. **Special JS Features or Syntax** None mentioned in the provided code snippet. However, it's worth noting that arrow functions were introduced in ECMAScript 2015 (ES6) and have become a popular way to write concise and readable code. **Benchmark Preparation Code** The script preparation code creates an array of objects with 100 elements each, using `for` loop. The `getProp` function is defined using `_memoize()`, which takes a string representing the property path and returns a memoized getter function. This function is then used in the benchmark to access the "id" property. **Alternative Approaches** Other approaches that could be used to measure the performance of the Lodash `_.map()` function might include: * Using a traditional function instead of an arrow function * Using a different library or implementation for memoization * Comparing the performance with and without caching * Measuring the performance on different types of data structures (e.g., arrays, objects, linked lists) Keep in mind that the chosen approach will depend on the specific requirements and use cases for the benchmark.
Related benchmarks:
Loop over object: lodash vs Object.entries fork by d9k 2
Loop over object: lodash vs Object.entries fork by d9k 3
Loop over object: lodash vs Object.entries 2
Loop over object: lodash vs Object.entries vs Object.values vs Object.keys (lodash 4.17.15)
test123_123
Comments
Confirm delete:
Do you really want to delete benchmark?