Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Underscore filter vs Array filter
(version: 0)
Underscore filter vs Array filter
Comparing performance of:
Underscore filter vs Array filter
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js'></script>
Script Preparation code:
var primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,97]
Tests:
Underscore filter
var result = _.filter(primes,(prime) => {return prime % 2 == 0});
Array filter
var result = primes.filter((prime) => {return prime % 2 == 0});
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Underscore filter
Array filter
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Underscore filter
1990546.1 Ops/sec
Array filter
8709297.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in the provided JSON benchmark. **Benchmark Definition** The benchmark is comparing two approaches to filtering an array of prime numbers: 1. Using the `filter()` method directly on an Array (`Array filter`). 2. Using the `_filter()` function from the Underscore.js library (`Underscore filter`). **Options compared** In this case, we're only comparing these two approaches. Pros and Cons: * **Array Filter**: + Pros: Native JavaScript functionality, easy to read and understand, doesn't require additional libraries. + Cons: May be slower than the Underscore.js implementation due to the overhead of creating a new function object, potential performance differences between browsers. * **Underscore Filter (using _filter())**: + Pros: Optimized for performance by the creator of the library, potentially faster execution due to caching and other optimizations. + Cons: Requires including an additional library (Underscore.js), may require additional setup or configuration. Other Considerations: * The benchmark is run on a Desktop platform with Chrome 120 browser, which might affect the results. To get more comprehensive results, it would be helpful to include tests for other browsers, platforms, and devices. * There's no comparison with other libraries or approaches that provide similar filtering functionality. **Underscore.js Library** Underscore.js is a popular JavaScript utility library created by Jeremy Ashkenas in 2009. Its main purpose is to provide functional programming utilities, making it easier to work with data and manipulate strings, arrays, and objects. The `_filter()` function is one of its core functions, which applies a callback function to each element in an array and returns a new array containing only the elements for which the callback returned `true`. **JavaScript Features/Syntax** There are no specific JavaScript features or syntax being tested in this benchmark. **Benchmark Preparation Code** The preparation code provided includes: * An array of prime numbers (`primes`) used as input for the filtering operations. * A script tag referencing the Underscore.js library, which is included before running the tests to ensure that the `_filter()` function is available. Overall, this benchmark provides a clear comparison between two approaches to filtering an array in JavaScript, highlighting potential performance differences and the benefits of using optimized libraries like Underscore.js.
Related benchmarks:
Underscore map vs Array map
Underscore each vs while
_.filter vs array filter (underscore)
underscore without vs filter
Comments
Confirm delete:
Do you really want to delete benchmark?