Re: question on Max and Min
- To: mathgroup at smc.vnet.net
- Subject: [mg80989] Re: question on Max and Min
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Fri, 7 Sep 2007 02:05:00 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <fbojr2$jeo$1@smc.vnet.net>
Arkadiusz.Majka at gmail.com wrote:
> Please take o while and think if
>
> Max[longList]-Min[longList]
>
> is the fastest way of calculating the difference of maximal and
> minimal values of (very) long list.
I would say yea for a one-dimensional list made of homogeneous atomic
elements (i.e. all element have the same basis type such as machine-size
floating-point numbers or integers).
The following example tests a vector of 100 million floating-point
numbers (occupying about 800 Mo in RAM) in less than 0.9 second. To me,
I would say the list is very large and the test fast enough. Of course,
you may have a different opinion. Also, sorting the list before talking
the first and last elements is much slower even when using Ordering. (I
believe that Max and Min have been optimized to work fast on large list.)
In[1]:= longList = RandomReal[{-10000, 10000}, {10^8}];
ByteCount[longList]
Max[longList] - Min[longList] // Timing
Out[2]= 800000076
Out[3]= {0.875, 20000.}
--
Jean-Marc