MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

2 Parts is faster than 1...

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33512] 2 Parts is faster than 1...
  • From: Chris Johnson <cjohnson at shell.faradic.net>
  • Date: Sun, 24 Mar 2002 01:44:19 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Can someone explain why...

cuts = {#1 #2, #1(1 - #2), (1 - #1)#3, (1 - #1)(1 - #3)} & @@@ 
      RandomArray[UniformDistribution[0, 1], {100000, 3}];
Dimensions[Select[cuts, Min[#] > .1 &]] // Timing

Calculates in about 1 second, but the equivalent (but I thought more
memory efficient)...

Dimensions[
    Select[{#1 #2, #1(1 - #2), (1 - #1)#3, (1 - #1)(1 - #3)} & @@@ 
        RandomArray[UniformDistribution[0, 1], {100000, 3}], 
      Min[#] > .1 &]] // Timing

Takes more than 4 times longer to compute.  

Note that if you take out the processing of the random array, the problem
isn't so strong, but still it seems the condensed code is faster by about 
10%.

In[73]:=
rnds=RandomArray[UniformDistribution[0,1],{100000,3}];
Dimensions[Select[rnds,Min[#]>.1&]]//Timing

Out[74]=
{1.532 Second,{72861,3}}

In[75]:=
Dimensions[
    Select[RandomArray[UniformDistribution[0,1],{100000,3}],
      Min[#]>.1&]]//Timing

Out[75]=
{1.742 Second,{73127,3}}

Look forward to hearing other peoples comments.
Chris




  • Prev by Date: RE: Getting Symbolic Real and Imag Parts? (Once Again)
  • Next by Date: Re: Re: Sinh[y]/y as y->0?
  • Previous by thread: Re: Axes for ListPlot3D
  • Next by thread: Global optimization codes