Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs Math (lodash 4.17.5) arr(5000)
(version: 1)
Comparing performance of:
_.min vs Math.min vs Lodash.max vs Math.max
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 Preparation code:
function getRandomInt(max) { return Math.floor(Math.random() * Math.floor(max)); } var arr = []; for(var i = 0; i < 5000; i++){ arr.push({value:getRandomInt(100)}); }
Tests:
_.min
_.min(arr);
Math.min
Math.min(...arr)
Lodash.max
_.max(arr)
Math.max
Math.max(...arr)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
_.min
Math.min
Lodash.max
Math.max
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 120 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.min
2218.2 Ops/sec
Math.min
3516.5 Ops/sec
Lodash.max
2158.3 Ops/sec
Math.max
3485.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided JSON represents a benchmark test case, which compares the performance of two approaches: Lodash's `min` and `max` functions, against their native equivalents in JavaScript. **Benchmark Preparation Code** The script preparation code generates an array of 5000 random objects with a single property "value" that is a random integer between 0 and 99. This array is used as input for the benchmark tests. **Html Preparation Code** The HTML preparation code includes a link to the Lodash library (version 4.17.5) in its minified form, which is required for the benchmark tests. **Test Cases** There are four test cases: 1. `_.min(arr);` - Uses Lodash's `min` function to find the smallest element in the array. 2. `Math.min(...arr)` - Uses the native JavaScript `Math.min` function with array spread syntax to find the smallest element in the array. 3. `_.max(arr)` - Uses Lodash's `max` function to find the largest element in the array. 4. `Math.max(...arr)` - Uses the native JavaScript `Math.max` function with array spread syntax to find the largest element in the array. **Comparison of Options** The benchmark tests compare the performance of two approaches: * **Lodash vs Native**: Using Lodash's `min`, `max`, and other functions versus their native equivalents in JavaScript. + Pros: - Easier to use for developers who are not familiar with the native implementation. - Often provides more features and options, such as error handling and support for multiple data types. + Cons: - May have a performance overhead due to the additional functionality and complexity of the Lodash library. * **Native vs Native**: Using the native JavaScript `Math.min` and `Math.max` functions versus each other. + Pros: - Typically has better performance compared to Lodash's implementation, as it is implemented in native code and optimized for the specific use case. + Cons: - May require more knowledge of JavaScript and its ecosystem to use correctly. **Other Considerations** When choosing between using Lodash or native JavaScript functions, consider the following factors: * **Performance**: If high performance is critical, native JavaScript functions may be a better choice. * **Ease of Use**: If ease of use and convenience are more important, Lodash's implementation may be preferred. * **Feature Set**: If you need specific features or functionality that is not available in the native implementation, Lodash may provide an alternative. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, object creation, and string formatting. The `min` and `max` functions are part of Lodash's core functionality and are used extensively in web development. **Special JS Feature/Syntax** The benchmark tests use the following special feature/syntax: * **Array Spread Syntax**: Used in the native JavaScript implementation to pass an array to a function, as shown in `Math.min(...arr)`. * **JavaScript Modules**: Not explicitly mentioned in the provided code, but it is worth noting that MeasureThat.net uses modules (import/export syntax) to load and execute scripts.
Related benchmarks:
Lodash max vs Math.max (lodash 4.7.11)
Lodash vs Array (lodash 4.17.5) arr(5000)
Lodash max vs JS Math.max (2022)
Lodash.isArray vs Array.isArray (Lodash v4.17.15)
Comments
Confirm delete:
Do you really want to delete benchmark?