Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.js vs Native _.min
(version: 0)
Comparing performance of:
Native vs Lodash.js filter
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
var max1 = 100000; // 100,000 (100 Thousand) var max2 = 10000000; // 10,000,000 (10 Million) var max3 = 100000000; // 100,000,000 (100 Million) var arr1 = []; //for (var i = 0; i <= max1; i++) { arr1.push(i); } var arr2 = []; for (var i = 0; i <= max2; i++) { arr2.push({x: i}); } var arr3 = []; //for (var i = 0; i <= max3; i++) { arr3.push(i); } function min(fn) { return (acc, item) => fn(acc) < fn(item || acc) ? acc : item; }
Tests:
Native
arr2.reduce(min(item => item.a))
Lodash.js filter
_.min(arr2, item => item.a);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native
Lodash.js filter
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
2.5 Ops/sec
Lodash.js filter
0.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the benchmark and explain what's being tested, the different options compared, their pros and cons, and other considerations. **Benchmark Overview** The benchmark measures the performance of two approaches to find the minimum value in an array: 1. Native (JavaScript built-in `min` function) 2. Lodash.js `min` function with a custom filtering callback **Native JavaScript min function** The native JavaScript `min` function is used to compare elements in the array and return the smallest one. In this benchmark, it's used to find the minimum value in the `arr2` array. **Lodash.js min function** Lodash.js is a popular JavaScript library that provides various utility functions, including `min`. The Lodash.js `min` function is similar to the native JavaScript version but takes an additional filtering callback as an argument. In this benchmark, the filtering callback is `(item) => item.a`. **Options Compared** Two options are compared: 1. Native JavaScript min function 2. Lodash.js min function with a custom filtering callback **Pros and Cons** Here's a brief summary of the pros and cons of each approach: **Native JavaScript min function:** Pros: * Fastest execution time (13.04 executions per second in the latest benchmark result) * Built-in function, so no additional library is needed * Simple to understand and implement Cons: * May not be as efficient for large arrays due to its inherent complexity * Limited control over filtering logic **Lodash.js min function with custom filtering callback:** Pros: * Flexible and customizable filtering logic * Can handle large arrays efficiently (1.66 executions per second in the latest benchmark result) Cons: * Requires additional library installation (Lodash.js) * Slower execution time compared to the native JavaScript implementation * More complex to understand and implement due to the callback function **Other Considerations** In this specific benchmark, the custom filtering logic `(item) => item.a` seems to be optimized for finding the minimum value in an array based on a single property (`a`). However, it's essential to consider more general cases where the filtering logic might need to change. Additionally, the Lodash.js `min` function can handle multiple filtering criteria by passing an object with multiple properties. This flexibility comes at the cost of slightly slower execution times compared to the native JavaScript implementation. **Library and Syntax Considerations** The Lodash.js library is a popular JavaScript utility library that provides various functions for common tasks, such as array manipulation, string manipulation, and more. The `min` function is one of these utilities, making it easy to include in projects with minimal code additions. There are no special JavaScript features or syntax used in this benchmark beyond the standard JavaScript built-in functions (e.g., `push`, `for`, `reduce`) and Lodash.js library functionality (specifically, the `min` function).
Related benchmarks:
Lodash.js vs Native isArrary
Lodash.js wrapper vs js native
Lodash.js(last) vs Native(at)
Lodash.js vs Native1
Comments
Confirm delete:
Do you really want to delete benchmark?