Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Math.max vs. custom max
(version: 0)
N/A
Comparing performance of:
Math.max vs Custom
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
let lowerBound = -Number.MAX_VALUE; function max() { let maximum = lowerBound; let i = arguments.length; while (i--) { arguments[i] > maximum && (maximum = arguments[i]) } return maximum; };
Tests:
Math.max
return Math.max(1,21,53,12,58,65,32,12,445,9382,132,12398,1239812, 21938721, 981, 91283, 1, 1, 1, 1, 1, 102183129312)
Custom
return max(1,21,53,12,58,65,32,12,445,9382,132,12398,1239812, 21938721, 981, 91283, 1, 1, 1, 1, 1, 102183129312)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Math.max
Custom
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.1:latest
, generated one year ago):
Let's break down the provided JSON to understand what's being tested and compared. **Benchmark Definition** The benchmark is called "Math.max vs. custom max", which suggests we're comparing two different approaches for finding the maximum value among a set of numbers. **Script Preparation Code** This code defines a custom `max` function that takes multiple arguments, iterates over them in reverse order, and returns the maximum value found. The lower bound is initialized to `-Number.MAX_VALUE` (a very large negative number) to ensure any input value will be greater than it. **Individual Test Cases** We have two test cases: 1. **Math.max**: This uses the built-in `Math.max` function, which takes multiple arguments and returns the maximum value. 2. **Custom**: This uses the custom `max` function defined in the Script Preparation Code. **Latest Benchmark Result** The latest benchmark result shows execution speeds for both `Math.max` and Custom approaches on a Chrome 89 browser running on Windows Desktop. Now, let's dive into what's being compared: **Comparison Points** * **Execution Speed**: The primary comparison point is the number of executions per second (EPS) for each approach. A higher EPS value indicates better performance. * **Built-in vs. Custom Functionality**: We're comparing a built-in function (`Math.max`) to a custom implementation. **Pros and Cons of Each Approach** * **Math.max**: + Pros: Built-in, optimized by browser vendors, likely to be very fast. + Cons: Limited control over implementation details, may not be suitable for all edge cases. * **Custom max function**: + Pros: More control over implementation details, can handle specific edge cases. + Cons: May not be as fast as built-in implementations, requires manual optimization. **Other Considerations** * **Edge Cases**: The custom `max` function might need to handle specific edge cases that the built-in `Math.max` function doesn't cover. In this case, the input values are all positive numbers. * **Browser Support**: Both approaches should work in most modern browsers, but there might be variations in performance depending on the browser's implementation. **Alternatives** Other alternatives for finding the maximum value include: * Using a library like Lodash (`.max` function) or Underscore.js (`.max` function) * Implementing other algorithms, such as using a priority queue * Using a language-specific feature, if available Note that these alternatives might not be directly comparable to the provided test cases.
Related benchmarks:
Math.max vs. custom algormithm
Javascript: reduce VS for with Math.max
array math.max (3 variants) vs for loop (4 variants)
array math.max (3 variants) vs for loop (5 variants)
Comments
Confirm delete:
Do you really want to delete benchmark?