Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.max vs Math.max
(version: 0)
Comparing performance of:
_.max vs Math.max
Created:
3 years 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/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.max
16178.9 Ops/sec
Math.max
20069.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in this benchmark. **Overview** The benchmark is comparing the performance of two functions: `_.max` from the Lodash library and `Math.max`. The test creates an array of 1000 objects, each with a random value between 0 and 100. The purpose of this test is to measure which function is faster in executing. **Options compared** Two options are being compared: 1. **_.max (Lodash)**: This function takes an array as input and returns the maximum value. 2. **Math.max**: This is a built-in JavaScript function that also takes an array as input and returns the maximum value. **Pros and Cons of each approach** 1. **_.max (Lodash)** * Pros: + More readable code, as it's part of a well-known library. + May be faster due to caching or other optimizations in Lodash. * Cons: + Adds an external dependency (Lodash), which may not be ideal for production environments. + May require additional setup or configuration. 2. **Math.max** * Pros: + No external dependencies, making it a more self-contained solution. + Highly optimized and implemented in native code, potentially leading to better performance. * Cons: + Less readable code, as it's not immediately apparent how to use `Math.max` with arrays. + May not have the same level of caching or optimization as Lodash. **Library: Lodash** Lodash is a popular JavaScript library that provides a set of functional programming helpers. The `_max` function is one of its utility functions, which is used here to compare performance. By using Lodash, the test creates more readable code and may benefit from optimizations implemented in the library. **Special JS feature/syntax (none mentioned)** There are no special JavaScript features or syntaxes being tested in this benchmark. The code uses standard JavaScript features like arrays, loops, and functions. **Other alternatives** If you want to compare other options, here are a few examples: 1. **Using `Array.prototype.reduce()`**: Instead of using Lodash's `_max` function, you could use the `reduce()` method on the array to find the maximum value. 2. **Using `Array.prototype.every()` and `Math.max()`**: You could create a custom implementation that uses `every()` to check if all elements in the array are less than or equal to the current max value, and then returns `Math.max()` with the initial value of 0. These alternatives would require more code and may not be as optimized as the original comparison using Lodash's `_max` function.
Related benchmarks:
Lodash max vs Math.max (lodash 4.7.11)
Labels
Lodash max vs JS Math.max (2022)
Lodash max vs Math.max 1.17.5
Comments
Confirm delete:
Do you really want to delete benchmark?