Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash filter length vs sumby
(version: 0)
Comparing performance of:
Filter length vs Sum vs Filter length native
Created:
8 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/lodash/4.16.2/lodash.min.js"></script>
Script Preparation code:
var array = [1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5, 1, 4, 3, 4, 2, 2, 1, 5, 3, 5];
Tests:
Filter length
const x = _.filter(array, i => i === 3).length
Sum
const x = _.sumBy(array, i => i === 3 ? 1 : 0)
Filter length native
const x = array.filter(i => i === 3).length
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Filter length
Sum
Filter length native
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):
**Benchmark Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided benchmark definition json and individual test cases are used to compare the execution performance of different approaches for filtering an array in JavaScript. **Benchmark Definition** The benchmark definition provides a set of rules for generating the input data and the executable code to be timed. In this case, there are three benchmark definitions: 1. `const x = _.filter(array, i => i === 3).length`: This definition uses Lodash's `filter` function to filter the array and then gets the length of the resulting array. 2. `const x = _.sumBy(array, i => i === 3 ? 1 : 0)`: This definition uses Lodash's `sumBy` function to sum up the elements in the array that match a certain condition (in this case, elements equal to 3). 3. `const x = array.filter(i => i === 3).length`: This definition uses the native JavaScript `filter` function to filter the array and then gets the length of the resulting array. **Individual Test Cases** Each test case represents an individual iteration of the benchmark. The test cases are: 1. `Filter length` 2. `Sum` 3. `Filter length native` These test cases are executed multiple times (not specified in the provided data) to generate a distribution of execution times. **Latest Benchmark Result** The latest benchmark result provides a snapshot of the execution performance of each test case on a specific machine: 1. `Filter length`: * Browser: Chrome 58 * DevicePlatform: Other * OperatingSystem: Windows * Execution frequency per second: 87959.8203125 2. `Filter length native`: * Browser: Chrome 58 * DevicePlatform: Other * OperatingSystem: Windows * Execution frequency per second: 69018.515625 3. `Sum`: * Browser: Chrome 58 * DevicePlatform: Other * OperatingSystem: Windows * Execution frequency per second: 67643.3984375 **Comparison** The benchmark results suggest that: * The Lodash-based implementation (`Filter length`) is the fastest, with an execution frequency of approximately 87959 times per second. * The native JavaScript `filter` function implementation (`Filter length native`) is slower than the Lodash-based implementation, but still relatively fast, with an execution frequency of approximately 69018 times per second. * The `Sum` test case is the slowest, with an execution frequency of approximately 67643 times per second. **Conclusion** The benchmark results suggest that using a library like Lodash can provide a performance boost for certain operations, such as filtering and summing arrays. However, native JavaScript implementations can still be competitive in terms of performance.
Related benchmarks:
unique elements in array using filter v2.3
unique elements in array using filter - large array
lodash flatmap long
lodash flatmap longest
Comments
Confirm delete:
Do you really want to delete benchmark?