Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
filter: Native vs Underscore vs Lodash
(version: 0)
Comparing performance of:
Native vs Underscore vs Lodash
Created:
5 years ago
by:
Registered User
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 src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js'></script>
Script Preparation code:
var randomArray = Array.apply(null, Array(100)).map(function() { return Math.round(Math.random() * 1000); }); function isBigEnough (value) { return value >= 10 } // Underscore was loaded last, so this saves an instance of underscore and resets _ to it's previous value (lodash). var _underscore = _.noConflict(); // This saves an instance of lodash and resets _ to it's previous value (undefined). var _lodash = _.noConflict();
Tests:
Native
var filtered = randomArray.filter(isBigEnough);
Underscore
var filtered = _underscore.filter(randomArray, isBigEnough);
Lodash
var filtered = _lodash.filter(randomArray, isBigEnough);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Native
Underscore
Lodash
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
838004.6 Ops/sec
Underscore
991316.5 Ops/sec
Lodash
916520.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **What is being tested?** The benchmark measures the performance difference between three approaches to filter an array of 100 random integers in JavaScript: 1. **Native**: The built-in `Array.prototype.filter()` method, which uses a simple iterative approach. 2. **Underscore**: A popular utility library for functional programming, which provides a `filter()` method implementation. 3. **Lodash**: Another well-known utility library, also providing a `filter()` method. **Options compared** The benchmark compares the performance of each approach: * Native: The built-in `Array.prototype.filter()` method, which uses a simple iterative approach. * Underscore: The `filter()` method implementation provided by the Underscore library. * Lodash: The `filter()` method implementation provided by the Lodash library. **Pros and cons** Here's a brief summary of each approach: * **Native**: Pros: + Fast, since it uses built-in methods and doesn't require any additional overhead. + Low memory usage. * Cons: + May have performance issues for large arrays due to the iterative approach. * **Underscore**: Pros: + Provides a convenient, functional programming-style interface for filtering arrays. + Can be useful for developers who prefer this style of programming. * Cons: + Requires including an additional library in the test environment. + May have slightly higher overhead compared to native methods. * **Lodash**: Pros: + Also provides a functional programming-style interface, but with more features than Underscore. + Can be useful for developers who prefer this style of programming and need more functionality. * Cons: + Requires including an additional library in the test environment. + May have higher overhead compared to native methods. **Library usage** The benchmark uses two utility libraries: 1. **Underscore**: A popular utility library for functional programming, which provides a `filter()` method implementation. 2. **Lodash**: Another well-known utility library, also providing a `filter()` method implementation. Both libraries are loaded last in the test environment, as specified in the benchmark configuration, to avoid conflicts with other libraries or built-in methods. **Special JavaScript features or syntax** None of the approaches mentioned above use any special JavaScript features or syntax that would require additional explanation. They all rely on standard JavaScript features and methods. **Other alternatives** If you're interested in alternative filtering methods, here are a few examples: * Using `Array.prototype.reduce()` and `Array.prototype.some()`: ```javascript var filtered = randomArray.reduce((acc, value) => { if (value >= 10) { acc.push(value); } return acc; }, []); ``` * Using `Array.prototype.forEach()` and `if` statements: ```javascript var filtered = []; randomArray.forEach(function(value) { if (value >= 10) { filtered.push(value); } }); ``` Keep in mind that these alternatives may have different performance characteristics compared to the native, Underscore, or Lodash approaches.
Related benchmarks:
Lodash vs Native Filters : BabbleTech 01
Lodash vs Native Filter
three lodash filter vs one native map
lodash.filter vs js native
Lodash filter VS native filter (with Lodash actually loaded)
Comments
Confirm delete:
Do you really want to delete benchmark?