Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Manually nested Tables faster than builtin nesting?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113459] Re: Manually nested Tables faster than builtin nesting?
  • From: "Carl K. Woll" <carlw at wolfram.com>
  • Date: Fri, 29 Oct 2010 06:30:00 -0400 (EDT)

On 10/28/2010 3:28 AM, Bob Hanlon wrote:
> I get similar results and Outer falls between the others.
>
> imax = jmax = 5000;
>
> (tabletable = Table[Table[i*j, {i, imax}], {j, jmax}];) //
>    Timing // First
>
> 1.96097
>
> (table = Table[i*j, {i, imax}, {j, jmax}];) // Timing // First
>
> 24.0062
>
> (outer = Outer[#1*#2&, Range[imax], Range[jmax]];) // Timing // First
>
> 14.2569
>
>    

Using Outer[Times, Range[imax], Range[jmax]] would be much, much faster:

In[17]:= table1 = Outer[#1*#2 &, Range[imax], Range[jmax]]; // Timing

Out[17]= {12.433, Null}

In[18]:= table2 = Outer[Times, Range[imax], Range[jmax]]; // Timing

Out[18]= {0.078, Null}

Carl Woll
Wolfram Research

> tabletable == table == outer
>
> True
>
>
> Bob Hanlon
>
> ---- Sebastian Schmitt<sschmitt at physi.uni-heidelberg.de>  wrote:
>
> =============
> Dear all!
>
> I find that manually nested Tables are faster (factor 2 in my example)
> compared to the builtin nesting. I probably do a stupid thinko. Could
> you please have a look?
>
> In[52]:= imax = jmax = 5000;
>
> In[53]:= (tabletable = Table[Table[i*j, {i, imax}], {j, jmax}];) //
>    Timing // First
>
> Out[53]= 1.84
>
> In[54]:= (table = Table[i*j, {i, imax}, {j, jmax}];) // Timing // First
>
> Out[54]= 14.55
>
> In[55]:= tabletable == table
>
> Out[55]= True
>
> Thanks,
>
> Sebastian
>
>
>    


  • Prev by Date: Re: If and Piecewise don't quite do what I need
  • Next by Date: Re: Visualization for Dummies
  • Previous by thread: Re: Manually nested Tables faster than builtin nesting?
  • Next by thread: Re: Manually nested Tables faster than builtin nesting?