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(10000);
Tests:
Strict
_.map(_.filter(array, function(n) { return n > 5000; }), function(n) { return {test: n}; });
Lazy
_(array).filter(function(n) { return n > 5000; }).map(function(n) { return {test: n}; }).value();
Lazy with one function
_(array).reduce(function(acc, n) { if(n > 5000) acc.push({test: n}); return acc; }, []);
Strict with one function
_.reduce(array, function(acc, n) { if(n > 5000) 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 help explain the benchmark. **Benchmark Overview** The benchmark tests different approaches for filtering and mapping a large array of numbers in JavaScript, using the popular `lodash` library. The test aims to compare the performance of these approaches on various browsers and devices. **Lodash Library** Lodash is a utility library that provides a collection of functions for functional programming, making it easier to write more concise and efficient code. In this benchmark, Lodash is used as the core function library, providing the `_.map`, `_.filter`, `_.reduce` methods, which are then modified in each test case. **Benchmark Test Cases** There are four test cases: 1. **Strict**: This approach uses `_.map` and `_.filter` directly on the array without any intermediate steps. 2. **Lazy**: This approach uses lazy evaluation by calling `_.filter` and `_.map` only when needed, using a closure function to create the mapping result. 3. **Lazy with one function**: This approach combines lazy evaluation with a single function call, reducing the overhead of multiple calls. 4. **Strict with one function**: This approach combines direct function calls with a single function execution. **Performance Comparison** The benchmark measures the number of executions per second (ExecutionsPerSecond) for each test case, which indicates how many times the code can execute within one second on each browser/device combination. The results show that: * Lazy and Lazy with one function approaches are faster than Strict and Strict with one function approaches. * The order of operations within the functions does not significantly impact performance. **Pros and Cons** Pros of Lazy approach: * Reduced overhead due to fewer function calls * Potential for better cache locality Cons of Lazy approach: * May require more memory due to intermediate results being stored * Can lead to slower initial execution times if the closure function is complex Pros of Strict with one function approach: * Direct execution without lazy evaluation may provide better performance in some cases * Simplified code may be easier to understand and maintain Cons of Strict with one function approach: * Potential for higher overhead due to multiple function calls * May not take advantage of lazy evaluation's benefits **Other Considerations** When writing benchmarks, it's essential to consider the following factors: * **Code quality**: Optimized code can lead to better performance. * **Cache locality**: Code that accesses data in a contiguous manner may benefit from cache coherence. * **Memory allocation**: Avoid allocating memory for temporary variables when not necessary. **Alternatives** Other approaches to consider: * Using native JavaScript functions (e.g., `filter`, `map`) instead of Lodash's implementations * Implementing custom, optimized filters and mappers for specific use cases * Utilizing modern JavaScript features, such as `for...of` loops or `async/await` syntax
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?