Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash max vs JS Math.max (2022)
(version: 0)
Comparing performance of:
Native js Math.max vs Lodash max
Created:
3 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.21/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:
Native js Math.max
Math.max(arr)
Lodash max
_.max(arr)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native js Math.max
Lodash max
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native js Math.max
46681.9 Ops/sec
Lodash max
15659.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Definition** The benchmark is comparing two approaches to find the maximum value in an array: using JavaScript's built-in `Math.max()` function versus using the popular utility library Lodash's `_.max()` function. **Script Preparation Code** The script preparation code generates a random array of 1000 objects, each with a random integer value between 1 and 100. This is done to create a large dataset that can be used to measure performance. **Html Preparation Code** The HTML preparation code includes a script tag that loads the Lodash library from a CDN. This allows us to test both native JavaScript's `Math.max()` function and the Lodash version in the same benchmark. **Individual Test Cases** There are two individual test cases: 1. **Native js Math.max**: Tests the performance of using JavaScript's built-in `Math.max()` function. 2. **Lodash max**: Tests the performance of using Lodash's `_.max()` function. **Pros and Cons:** * **Native js Math.max**: Pros: + Widely supported and optimized by browsers. + Typically faster since it's a native function. Cons: + May not be as robust or customizable as other approaches. * **Lodash max**: Pros: + More flexible and customizable than native `Math.max()`. + Can handle more complex data structures and edge cases. Cons: + Slower due to the overhead of loading and executing a library function. + May not be supported by older browsers or systems. **Library: Lodash** Lodash is a popular utility library for JavaScript that provides a wide range of functions for tasks like array manipulation, object manipulation, and more. In this benchmark, it's used for its `_.max()` function, which implements a efficient algorithm for finding the maximum value in an array. **Special JS Feature/Syntax: None** There are no special JavaScript features or syntax being tested in this benchmark. **Other Alternatives:** If you wanted to test alternative approaches, you could consider using other libraries like: * **Array.prototype.max()` (ES6+): A more modern and efficient approach that's supported by many browsers. * **Math.max.apply()`: An older approach that uses `Math.max()` with the `apply()` method to apply it to an array. Keep in mind that these alternatives might have different performance characteristics, so they'd need to be tested separately.
Related benchmarks:
Lodash max vs Math.max (lodash 4.7.11)
Lodash min vs Math.min (lodash 4.7.11)
Labels
_.max vs Math.max
Comments
Confirm delete:
Do you really want to delete benchmark?