Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash partition vs ES6 (KAP
(version: 0)
Comparison of using lodash partition against raw ES6
Comparing performance of:
_.partition vs ES6 partition
Created:
2 years ago
by:
Guest
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 Preparation code:
var arr = [ [ "Wingman Identification Letter/Number", "A" ], [ "Force Tell Indicator", false ], [ "Mission Commander Indicator", false ], [ "Geodetic Position Quality", ">18080 FT" ], [ "Air Platform", "CIVIL, AIRLINER" ], [ "J-Series", "J2.2" ], [ "Active Relay Indicator, Voice Channel", false ], [ "R2 is Held", false ], [ "Speed (Knots)", 477.9369349024706 ], [ "Emergency Indicator", false ], [ "Identity", "FRIEND" ], [ "Course", 139 ], [ "Active Relay Indicator, WAN", false ], [ "Exercise Indicator", false ], [ "Network Participation Status Indicator", "ACTIVE-NON SPECIFIC" ], [ "Is Command Objective", false ], [ "PCT_Identifiers", { "PCT": "P-68383", "PCT L16": "43756" } ], [ "Altitude (M)", 14417.04 ], [ "Air Activity", "XRAY" ], [ "Environment", "AIR" ], [ "Track Number, Mission Commander", "45354" ], [ "Simulation Indicator", true ], [ "Is Connection Target", false ], [ "Airborne Indicator", true ], [ "Time of Reception", "2024-02-19T14:21:26.903866Z" ], [ "Speed (M/S)", 245.87199999921322 ], [ "Control Channel", 42 ], [ "Voice Call Sign Indicator", false ], [ "Flight Leader Indicator", false ], [ "Voice Frequency/Channel", "Channel A 4" ], [ "Record Status", "Remote" ], [ "Speed (DMH)", 484 ], [ "PCT_Display_TN", "43756" ], [ "NonC2 JU-to-NonC2 JU NPG Status B", false ], [ "IsEntity", true ], [ "Bailout Indicator", false ], [ "NonC2 JU-to-NonC2 JU NPG Status A", false ], [ "RTT Reply Status Indicator", false ], [ "Altitude (Ft)", 47300 ], [ "Track Number, Source", "43756" ], [ "Command and Control Indicator", false ], [ "Net Number, NonC2 JU-to-NonC2 JU NPG B", 42 ], [ "Net Number, NonC2 JU-to-NonC2 JU NPG A", 23 ], [ "Active Relay Indicator, Control Channel", false ] ]
Tests:
_.partition
_.partition(arr, (attr) => _.isBoolean(attr[1]));
ES6 partition
const partition = (arr, predicate) => { return [ ...arr.filter(predicate), ...arr.filter(el => !predicate(el)) ] }; partition(arr, (attr) => _.isBoolean(attr[1]));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.partition
ES6 partition
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.partition
344529.8 Ops/sec
ES6 partition
171132.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks and explore what's being tested in this specific benchmark. **What is being tested?** The benchmark compares two approaches for filtering an array: using Lodash's `partition` function versus implementing it manually using ES6 syntax. **Options compared** Two options are being compared: 1. **Lodash's `partition` function**: This function takes two arguments, the input array and a predicate function. The predicate function is applied to each element in the array, and elements for which the predicate returns `true` are included in the first output array, while elements for which the predicate returns `false` are included in the second output array. 2. **Manual implementation using ES6 syntax**: This approach uses the spread operator (`...`) to create two new arrays: one with elements that pass the predicate test and another with elements that don't. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: **Lodash's `partition` function** Pros: * Concise and readable code * Built-in functionality, reducing boilerplate code * Probably faster due to optimized implementation Cons: * Requires an additional library dependency (Lodash) * Might not be as efficient as a custom implementation for very large datasets **Manual implementation using ES6 syntax** Pros: * No external dependencies required * Can be customized and optimized for specific use cases * Might be faster for very large datasets due to reduced overhead Cons: * More verbose code compared to the Lodash version * Requires more manual care for edge cases (e.g., handling null or undefined elements) **Which one is faster?** According to the latest benchmark results, Lodash's `partition` function appears to be slightly faster than the manual implementation. However, it's essential to note that this result might not hold true for all use cases, and the manual implementation can still be a viable option depending on specific requirements. **Additional context** The benchmark is run using Chrome 121 on Windows Desktop, and the `ExecutionsPerSecond` value indicates the number of executions per second. The Lodash version yields around 344529 executions per second, while the ES6 implementation produces approximately 171132 executions per second. I hope this explanation helps you understand the JavaScript microbenchmarking world!
Related benchmarks:
_.includes vs includes() vs indexof
Lodash partition VS native reduce
Lodash omit Vs. es6 rest spread random keys
Lodash partition vs ES6 for..of partition
Lodash partition VS native reduce (with Lodash actually loaded)
Comments
Confirm delete:
Do you really want to delete benchmark?