Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Chain vs &&
(version: 0)
Comparing performance of:
Chain vs Without chain
Created:
5 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 data = Array(10000000).fill({ a: 'a', b: 1 });
Tests:
Chain
_.chain(data).filter(f => f.a === 'a').filter(f => f.b === 1).map(f => f.a).value()
Without chain
data.filter(f => f.a === 'a' && f.b === 1).map(f => f.a)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Chain
Without chain
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0
Browser/OS:
Chrome 130 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Chain
3.6 Ops/sec
Without chain
4.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases to understand what is being tested. **Benchmark Definition** The benchmark definition json contains two main components: 1. **Script Preparation Code**: This code snippet initializes an array of 10,000,000 objects with two properties: `a` and `b`. The `data` variable is assigned this value. 2. **Html Preparation Code**: This code snippet includes the Lodash JavaScript library from a CDN, which will be used in the benchmark. **Test Cases** The benchmark definition contains two individual test cases: 1. **"Chain"`**: This test case uses the Lodash `chain()` function to create a pipeline of operations on the `data` array. * The first filter (`_.chain(data).filter(f => f.a === 'a')`) filters out elements where `a` is not equal to `'a'`. * The second filter (`_.filter(f => f.b === 1)`) filters out elements where `b` is not equal to `1`. * The map function (`_.map(f => f.a)`) maps each element to its value for the property `a`. * The final `.value()` method returns the result of the entire pipeline. 2. **"Without chain"`**: This test case uses a traditional JavaScript approach without Lodash's chaining functionality. * The first filter (`data.filter(f => f.a === 'a' && f.b === 1)`) filters out elements where `a` is not equal to `'a'` and `b` is not equal to `1`. * The second filter (`_.map(f => f.a)` is incorrect here, it should be `.map(f => f.a)`) maps each element to its value for the property `a`. **Options Compared** The benchmark compares two approaches: 1. **Lodash chaining**: This approach uses Lodash's utility functions to create a pipeline of operations on the `data` array. 2. **Traditional JavaScript filtering and mapping**: This approach uses native JavaScript methods (filter, map) without Lodash's chaining functionality. **Pros and Cons** * **Lodash Chaining**: + Pros: More readable code, less chance of errors due to correct order of operations. + Cons: Additional overhead due to the need to import and initialize the Lodash library, potential performance impact if not used efficiently. * **Traditional JavaScript Filtering and Mapping**: + Pros: No additional overhead, potentially faster execution since there is no unnecessary function call overhead. + Cons: Less readable code, more chance of errors if the order of operations is incorrect. **Library Usage** The benchmark uses Lodash version 4.17.5. Lodash is a popular JavaScript library that provides a wide range of utility functions for tasks such as: * Data manipulation (filter, map, reduce) * String and array manipulation * Object manipulation * Functional programming utilities In this case, Lodash's `chain()` function enables the use of a pipeline approach to filter and transform data in a more readable way. **Special JS Feature or Syntax** There are no special JavaScript features or syntax used in these test cases.
Related benchmarks:
Spread Operator vs Lodash Small Array
Spread Operator vs Lodash with not so many items
Join: Lodash vs Native
Spread Operator vs Lodash [2]
Array From vs lodash clone
Comments
Confirm delete:
Do you really want to delete benchmark?