Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Streams vs Vanilla Javascript v2
(version: 1)
Comparing performance of:
Lodash vs Vanilla Javascript
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
function getRandomInt(max) { return Math.floor(Math.random() * Math.floor(max)); } var arr = []; for(var i = 0; i < 100000; i++){ arr.push({valueF:getRandomInt(100), valueM:getRandomInt(100)}); }
Tests:
Lodash
result = _(arr) .filter((value) => value.valueF > 50 ) .map((value) => ({ "value": value.valueM })) .value(); console.log(result);
Vanilla Javascript
const result = arr .filter(value => value.valueF > 50) .map(value => ({ value: value.valueM })); console.log(result);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash
Vanilla Javascript
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Browser/OS:
Chrome 125 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
106.3 Ops/sec
Vanilla Javascript
132.2 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
In this benchmark, test cases measure the performance difference between using the Lodash library for functional programming style and Vanilla JavaScript for similar data manipulations on an array of objects. ### Benchmark Overview 1. **Name**: Lodash Streams vs Vanilla JavaScript v2 2. **Purpose**: Compare the performance of Lodash against native JavaScript methods for filtering and mapping through an array of objects. ### Test Cases #### Lodash Implementation: ```javascript result = _(arr) .filter((value) => value.valueF > 50) .map((value) => ({ "value": value.valueM })) .value(); console.log(result); ``` #### Vanilla JavaScript Implementation: ```javascript const result = arr .filter(value => value.valueF > 50) .map(value => ({ value: value.valueM })); console.log(result); ``` ### Comparison of Options #### 1. **Lodash Library**: - **Description**: Lodash is a JavaScript library that provides utility functions for common programming tasks, including manipulating and iterating over arrays and objects. - **Features Cons**: - Pros: Provides a more readable and expressive way to handle array and object transformations, can chain methods seamlessly. - Cons: Introduces additional overhead due to the library weight and extra function calls, which can impact performance, especially for simple tasks. #### 2. **Vanilla JavaScript**: - **Description**: Uses built-in JavaScript array methods (`filter` and `map`). - **Features Cons**: - Pros: Typically more performant for simpler operations since there's no overhead of an external library; direct access to JavaScript's core functionality without any additional loading. - Cons: May require more boilerplate or lower-level understanding of JavaScript for complex transformations compared to Lodash, where chaining can simplify the code. ### Performance Results Based on the benchmark results: - **Lodash** achieved approximately **1196.34 executions per second**. - **Vanilla JavaScript** achieved approximately **973.01 executions per second**. This indicates that in this specific case, Lodash was faster, likely due to optimizations in the library for handling larger datasets, despite the common perception that native methods are generally preferable for performance. ### Other Considerations - **Browser Environment**: Benchmarks were run in Mobile Safari on iOS, and the performance can vary significantly across different environments and platforms. - **Use Case**: When choosing between Lodash and Vanilla JavaScript, consider the complexity of the functionality required. For complex data transformations that benefit from chaining, Lodash may provide cleaner and more maintainable code. For simpler or performance-critical applications, plain JavaScript may be the better choice. - **Alternatives**: Other libraries like Underscore.js offer similar functionality to Lodash but might have different performance characteristics. Native JavaScript also has evolved over time, with features like arrow functions and the spread operator enhancing its expressiveness. Additionally, adopting modern practices such as using `forEach`, `reduce`, and other Array methods can also achieve similar goals efficiently. In conclusion, engineers need to weigh the trade-offs between using a utility library like Lodash versus raw JavaScript considering readability, maintainability, performance, and context of use when developing their applications.
Related benchmarks:
Lodash max vs Math.max
Lodash max vs Math.max (lodash 4.7.11)
Lodash min vs Math.min (lodash 4.7.11)
Lodash vs Math (lodash 4.17.5) arr(5000)
Lodash maxBy vs Math.max & Map
Lodash max vs Math.max 2k datapoints
Lodash min & max vs math.min & math.max vs for loop
Lodash max vs JS Math.max (2022)
Lodash Streams vs Vanilla Javascript
Comments
Confirm delete:
Do you really want to delete benchmark?