Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash each vs loop over entries on objects
(version: 0)
Comparing performance of:
lodash vs vanilla
Created:
3 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:
var person = JSON.stringify({ first_name: "first", last_name: "last", age: 5, random: "19284984343", }) var ourObj = { a12345: person, b1234: person, c: person, d: person }
Tests:
lodash
_.chain(ourObj) .map((val, key) => { const json = JSON.parse(val) return { key: json } }) .filter(Boolean) .value()
vanilla
let entries = Object.entries(ourObj) let arr = [] for (let i in entries) { const json = JSON.parse(entries[i][1]) arr.push({ [entries[i][0]] : json}) } arr.filter(Boolean)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash
vanilla
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 provided benchmark measures two approaches to processing objects in JavaScript: 1. **Lodash**: Using the `lodash` library, which provides utility functions for functional programming, array manipulation, and object iteration. 2. **Vanilla**: A vanilla JavaScript implementation, without any external libraries. **What's tested?** In this benchmark, we're comparing the performance of two methods to process an object: * **Lodash**: The `_.chain()` method is used to create a pipeline of functions that operate on the input object (`ourObj`). Specifically, it uses `_map()`, `_filter(Boolean)`, and finally `_value()` to transform the data. * **Vanilla**: A manual implementation using a `for...in` loop to iterate over the object's entries, parse each value as JSON, and construct a new array of transformed objects. **Options compared** The two approaches differ in their use of external libraries (Lodash) vs. built-in JavaScript functions (vanilla). **Pros and Cons:** * **Lodash**: + Pros: - Easier to read and maintain due to the use of a well-established library. - Provides a familiar API for common data transformations. + Cons: - Includes an external dependency, which may impact performance or security (depending on how it's included in the project). * **Vanilla**: + Pros: - No external dependencies, which can improve performance and reduce security risks. - Allows developers to control the implementation details. + Cons: - More verbose code, requiring more manual effort for setup and error handling. **Library: Lodash** Lodash is a popular JavaScript library that provides a comprehensive set of utility functions for functional programming, array manipulation, and object iteration. Its `chain()` method allows creating a pipeline of functions that operate on the input data, making it easier to write concise and readable code. In this benchmark, we're using Lodash version 4.17.5. **Special JS feature: None** There are no special JavaScript features or syntax used in this benchmark beyond what's typically available in modern browsers. **Alternative approaches** Other alternatives for processing objects could include: 1. **Using `Array.prototype.map()` and other array methods**: This approach would involve transforming the object's values using array methods, such as `map()`, `filter()`, and `reduce()`. 2. **Using a custom object iterator**: This approach would require implementing a custom iterator function to process each property in the object. 3. **Using a library like Ramda or Purescript**: These libraries provide functional programming utilities that could be used instead of Lodash. These alternatives might offer different trade-offs between performance, readability, and maintainability, depending on the specific use case and requirements.
Related benchmarks:
Object.assign vs Lodash.assign
Object.assign vs Lodash.merge
Lodash.assign vs Object.assign
native find vs lodash _.find for objects equality
Object.assign vs Lodash.omit
Comments
Confirm delete:
Do you really want to delete benchmark?