Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash max vs Math.max 4.17.15
(version: 0)
Comparing performance of:
_.max vs Math.max
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/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 < 1000; i++){ arr.push({value:getRandomInt(100)}); }
Tests:
_.max
_.max(arr);
Math.max
Math.max(...arr)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.max
Math.max
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.max
9722.6 Ops/sec
Math.max
15874.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark data and explain what's being tested. **Benchmark Overview** The benchmark is designed to compare the performance of two approaches: using the built-in `Math.max` function in JavaScript, and using the `_max` function from the Lodash library. The test case creates an array of 1000 objects with random integer values between 0 and 100, and then measures the execution time of each approach. **Comparison Options** Two options are being compared: 1. **Math.max**: This is a built-in JavaScript function that returns the maximum value from an iterable (such as an array). It's a simple and widely supported function. 2. **_.max` from Lodash**: This function is part of the popular Lodash library, which provides a collection of high-quality, customizable functions for various tasks, including array manipulation. **Pros and Cons** * **Math.max**: + Pros: Simple, widely supported, easy to use. + Cons: May not be optimized for performance, may have limitations on input types or sizes. * _.max` from Lodash: + Pros: Optimized for performance, provides additional features like handling edge cases and sorting. + Cons: Requires an external library (Lodash), adds overhead in terms of download size and initialization time. **Library Usage** The test case uses the Lodash library, which is a popular choice for its extensive feature set and high-quality code. The `_max` function from Lodash is being used to compare with the built-in `Math.max` function. **Special JS Features or Syntax** There are no special JavaScript features or syntaxes mentioned in this benchmark. The test case only uses standard JavaScript syntax and functions. **Alternative Approaches** If you wanted to add additional approaches to the benchmark, some alternatives could include: * Using a custom implementation of `Math.max` (e.g., using a loop with index checking) * Using another library or framework for array manipulation (e.g., Array.prototype.reduce()) * Implementing a different algorithm for finding the maximum value (e.g., sorting the array) These alternative approaches would require modifications to the test case script and might add additional overhead or complexity. In summary, this benchmark compares two widely used JavaScript functions for finding the maximum value in an array: `Math.max` and `_max` from Lodash. The results highlight the performance benefits of using optimized libraries like Lodash, but also demonstrate the simplicity and widespread adoption of built-in functions like `Math.max`.
Related benchmarks:
Lodash max vs Math.max (lodash 4.7.11)
Labels
Lodash max vs JS Math.max (2022)
_.max vs Math.max
Lodash.isArray vs Array.isArray (Lodash v4.17.15)
Comments
Confirm delete:
Do you really want to delete benchmark?