DescriptionPerformance improvement for Math.max and Math.min
The old code for Math.max was computing -Infinity for each call, and
doing N comparisons for N arguments, the first comparison guaranteed
to be fairly slow because it is against -Infinity.
The new code does N-1 comparisons, which are all SMI comparisons if
the arguments are all SMIs.
Timings, in ns/call over 2M calls. The functions were run on several
workloads - SMIs or heap nums, arguments ascending or descending.
Times quoted are the best of 5 runs, the high and low ranges for the
'easiest' and 'hardest' workload.
Old:
Arguments: 0 1 2 3 4
Math.min : 20-21 40-45 45-58 70-108 83-142
Math.max : 69-72 88-89 96-116 117-156 133-188
New:
Math.min : 19-20 19-24 26-47 42-88 52-112
Math.max : 19-20 19-23 26-46 41-85 52-111
Above times include timing loop and call overhead of:
12 13 8 15 16
For typical use Math.max is 2.5-3.7x faster.
Math.min is 1.2-1.7x faster.
Committed as V8 bleeding edge revision 3433
Patch Set 1 #Patch Set 2 : '' #Patch Set 3 : '' #Patch Set 4 : '' #
Total comments: 2
Patch Set 5 : '' #Messages
Total messages: 7 (0 generated)
|