Re: Re: Curious Timing Results
- To: mathgroup at smc.vnet.net
- Subject: [mg38736] Re: [mg38717] Re: Curious Timing Results
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Tue, 7 Jan 2003 07:27:08 -0500 (EST)
- References: <av36rc$g08$1@smc.vnet.net> <200301060845.DAA03489@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Jens-Peer Kuska wrote: > > Hi, > > In[]:=Developer`PackedArrayQ /@ {x, y} > > Out[]={True,False} > > Some times PackedArrays are slower -- you have found one. > I expect, that the x Array must be unpacked and this cause > the longer time in Inner[Divide,x,x] > > Regards > Jens > > Chris Grant wrote: > > > > I find the Timing results below a little curious. Is there a simple > > explanation why I shouldn't? > > > > Chris Grant > > > > In[1]:= x = Table[2.,{i,100000}]; > > > > In[2]:= y = Table[If[i<1000000,2.,i],{i,100000}]; > > > > In[3]:= SameQ[x,y] > > > > Out[3]= True > > > > In[4]:= Timing[Inner[Divide,x,x]] > > > > Out[4]= {0.44 Second,100000.} > > > > In[5]:= Timing[Inner[Divide,y,y]] > > > > Out[5]= {0.321 Second,100000.} As Jens-Peer Kuska and Andrzej Kozlowski both hypothesized, unpacking is the issue. Specifically, this is done by Inner. One can improve speed for this sort of computation by using operations that do not need to unpack. In[3]:= x = Table[2.,{i,100000}]; In[4]:= y = Table[If[i<1000000,2.,i],{i,100000}]; In[5]:= Timing[Inner[Divide,x,x]] Out[5]= {0.27 Second, 100000.} In[6]:= Timing[Inner[Divide,y,y]] Out[6]= {0.16 Second, 100000.} In[7]:= Timing[Apply[Plus,x/x]] Out[7]= {0.06 Second, 100000.} In[8]:= Timing[Apply[Plus,y/y]] Out[8]= {0.12 Second, 100000.} Daniel Lichtblau Wolfram Research
- References:
- Re: Curious Timing Results
- From: Jens-Peer Kuska <kuska@informatik.uni-leipzig.de>
- Re: Curious Timing Results