jashkenas/underscore — pull request #1448 by mehdishojaei (2014-02-02 21:31:37+00:00)
Title: Optimize _.max and _.min for performance

One optimization applied to `_.max` and `_.min` to prevent object creation in their loops. This change affects when passing large lists (length >= 65535) to this functions.

Performance gain depends on the arrangement of the passed lists to this functions:
An ascending sorted list is a bad arrangement for the `_.max` and a descending sorted list is bad for the `_.min`.

I prepared 4 jsPerfs to show you performance gains of this changes:
(`_.max` and `_.min` are the current version and `_.max2` and `_.min2` are the new version of this functions.)

`_.max` on a large randomly arranged list: [_.max(randomList)](http://jsperf.com/underscores-max-random-list/3)
`_.min` on a large randomly arranged list: [_.min(randomList)](http://jsperf.com/underscores-min-random-list/3)
`_.max` on a large bad arranged list: [_.max(badList)](http://jsperf.com/underscores-max-bad-list/3)
`_.min` on a large bad arranged list: [_.min(badList)](http://jsperf.com/underscores-min-bad-list/3)