MathGroup Archive 2005

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

Search the Archive

Re: Re: Timing runs for the last part of my previous post

  • To: mathgroup at smc.vnet.net
  • Subject: [mg62196] Re: Re: Timing runs for the last part of my previous post
  • From: Maxim <ab_def at prontomail.com>
  • Date: Mon, 14 Nov 2005 00:38:41 -0500 (EST)
  • References: <dkshq9$jei$1@smc.vnet.net> <200511100750.CAA07305@smc.vnet.net> <dl1jjb$t8d$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Fri, 11 Nov 2005 08:09:15 +0000 (UTC), Oyvind Tafjord  
<tafjord at wolfram.com> wrote:

>
> Here's yet another way which is about 30% faster then testFunc4:
>
> Pick[values, Plus @@ Sign[#] & /@ values, -2]
>
> At some point you'll need to process all pairs in the list, so it's  
> faster
> to do this up front, in an effective way, and then use Pick to get the
> elements you want.
>
> Oyvind Tafjord
> Wolfram Research
>
>

An even more efficient (and contrived) way is to make all the loops over  
the list elements implicit:

In[1]:=
L = Array[Random[Integer, {-10, 10}]&, {10^6, 2}];
Cases[L, {_?Negative, _?Negative}]; // Timing
Pick[L, Plus@@ Sign@ #& /@ L, -2]; // Timing
Pick[L, Total@ Transpose@ Sign@ L, -2]; // Timing

Out[2]= {1.563*Second, Null}

Out[3]= {1.062*Second, Null}

Out[4]= {0.468*Second, Null}

The second version uses Map, which is fairly efficient but still not as  
good as applying listable functions to vectors.

Maxim Rytin
m.r at inbox.ru


  • Prev by Date: Re: Re: Types in Mathematica
  • Next by Date: Re: Bug in pattern parsing?
  • Previous by thread: Re: Re: Timing runs for the last part of my previous post
  • Next by thread: Re: Re: Re: Timing runs for the last part of my previous post