Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Test lodash v2
(version: 0)
Comparing performance of:
Strict vs Lazy vs Lazy with one function vs Strict with one function
Created:
9 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/lodash/4.16.0/lodash.min.js"></script>
Script Preparation code:
var array = _.range(1000);
Tests:
Strict
_.map(_.filter(array, function(n) { return n > 998; }), function(n) { return {test: n}; });
Lazy
_(array).filter(function(n) { return n > 998; }).map(function(n) { return {test: n}; });
Lazy with one function
_(array).reduce(function(acc, n) { if(n > 998) acc.push({test: n}); return acc; }, []);
Strict with one function
_.reduce(array, function(acc, n) { if(n > 998) acc.push({test: n}); return acc; }, []);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Strict
Lazy
Lazy with one function
Strict with one function
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'd be happy to explain what's being tested in the provided JSON benchmark. **Benchmark Overview** The test cases measure the performance of two approaches for filtering and mapping an array using Lodash, a popular JavaScript utility library. The two approaches are: 1. **Strict**: Directly using Lodash's `map` function with a filter callback. 2. **Lazy**: Using Lodash's `_` alias (a shorthand for Lodash) to create a pipeline of operations, where the filtering and mapping are performed lazily. **Lodash Library** Lodash is a utility library that provides a wide range of functions for working with arrays, objects, and more. In this benchmark, Lodash's `map`, `filter`, and `_` alias are used. The `_` alias is used to create a pipeline of operations, which is the "lazy" approach. **Test Cases** The test cases measure the performance of each approach: 1. **Strict**: Directly using `_.map(_.filter(array, function(n) { return n > 998; }), function(n) { return {test: n}; });` * This approach uses `_.map` to apply a transformation function to each element in the filtered array. 2. **Lazy**: * **Lazy with one function**: `_([1,2,...])_.filter(function(n) { return n > 998; }).map(function(n) { return {test: n}; });` + This approach uses Lodash's `_` alias to create a pipeline of operations. + The `filter` operation is performed lazily on the original array, reducing its size dynamically. * **Strict with one function**: `_.reduce(array, function(acc, n) { if(n > 998) acc.push({test: n}); return acc; }, []);` + This approach uses Lodash's `reduce` method to iterate over the array and perform an accumulation operation. **Performance Comparison** The benchmark measures the execution speed of each approach, which is reported as `ExecutionsPerSecond`. The results show that: * The **Lazy with one function** approach is the fastest, with a higher executions per second value. * The **Strict** approach is slower than both lazy approaches. * The **Strict with one function** approach is faster than the direct `_.map` approach but still slower than the lazy approaches. **Pros and Cons** Here are some pros and cons of each approach: 1. **Lazy with one function**: * Pros: Faster execution speed, less memory allocation, and better cache locality. * Cons: May be more complex to understand and maintain due to pipeline operations. 2. **Lazy (using _)**: * Pros: Simplifies code and reduces boilerplate, can be more readable and maintainable. * Cons: May incur additional overhead due to the pipeline operation. 3. **Strict**: * Pros: Easy to understand and maintain, no unnecessary complexity. * Cons: Slower execution speed, more memory allocation. **Special Features** In this benchmark, we're using some special JavaScript features: * `_` alias for Lodash functions (e.g., `_.map`, `_.filter`) * Arrow functions (`function(n) { return {test: n}; }`) * Reduced function calls and pipeline operations Overall, the lazy approaches are faster due to reduced memory allocation and better cache locality. However, they can be more complex to understand and maintain. The strict approach is easier to understand but slower.
Related benchmarks:
lodash range vs Array.from vs keys() + spread
lodash range vs Array.from vs keys() + spread 234das
Length vs Lodash Size 100k
Spread Operator vs Lodash [2]
Array From vs lodash clone
Comments
Confirm delete:
Do you really want to delete benchmark?