Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Object/Array map vs native
(version: 0)
Comparing performance of:
Native Object Map vs Lodash Object Map vs js Map vs lodash Array Map
Created:
4 years ago
by:
Guest
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:
const obj = { '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12, '13': 13 } function mapper(el) { return el + 10 } function lodashObjectMap () { res = _.map(obj, mapper) console.log(res) } function jsValuesMap () { res = Object.values(obj).map(mapper) console.log(res) } const arr = [1,2,3,4,5,6,7,8,9,10,11,12,13] function lodashArrayMap() { res = _.map(arr, mapper) console.log(res) } function jsMap(){ res = arr.map(mapper) console.log(res) }
Tests:
Native Object Map
jsValuesMap()
Lodash Object Map
lodashObjectMap()
js Map
jsMap()
lodash Array Map
lodashArrayMap()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Native Object Map
Lodash Object Map
js Map
lodash Array Map
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
gemma2:9b
, generated one year ago):
This benchmark compares the performance of mapping objects and arrays using both native JavaScript methods and Lodash. **Here's a breakdown:** * **What is being tested?** The benchmark measures how efficiently different approaches map (transform) values within objects and arrays. * **Options being compared:** * **`jsValuesMap()`:** Uses `Object.values(obj)` to get an array of object values, then applies the `mapper` function to each value using `.map()`. This is a native JavaScript approach for mapping object values. * **`lodashObjectMap()`:** Uses Lodash's `_.map()` function to map the values of the `obj` object. * **`jsMap()`:** Uses native JavaScript's `.map()` method directly on an array (`arr`) to apply the `mapper` function to each element. * **`lodashArrayMap()`:** Uses Lodash's `_.map()` function to map the elements of the `arr` array. * **Pros and Cons:** * **Native JavaScript methods:** Generally lightweight and performant as they are built into the language itself. * **Lodash:** Offers convenience and additional functionalities (not directly tested here), but can introduce overhead due to the library size and potential function calls. * **Considerations:** * **Object vs Array Mapping:** The benchmark considers both object values and arrays, as mapping operations are common for both data structures. * **Mapper Function Complexity:** The `mapper` function is simple in this case (adding 10 to each element). More complex mappings could influence performance comparisons. * **Alternatives:** * **For-loops:** While not explicitly tested here, using a traditional `for` loop for mapping could be an alternative. However, `.map()` methods are often preferred for their conciseness and readability. * **Functional programming libraries:** Libraries like Ramda or Immutable.js offer specialized functions for data manipulation that might provide alternative approaches to mapping. Let me know if you have any more questions!
Related benchmarks:
Array.prototype.map vs Lodash.map
lodash map vs es6 map v2
array.map vs _.map
lodash map vs es6 Object.values.map
Comments
Confirm delete:
Do you really want to delete benchmark?