MathGroup Archive 2003

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

Search the Archive

Re: Timing of Table

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43255] Re: Timing of Table
  • From: "Carl K. Woll" <carlw at u.washington.edu>
  • Date: Sat, 23 Aug 2003 08:08:29 -0400 (EDT)
  • Organization: University of Washington
  • References: <bi18ce$afl$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Mariusz,

The difference in timing comes from the use of packed arrays. When Table can
determine that the number of elements it will generate is at least 250, and
that it's output will be an array of numbers, then it will use packed array
code, which is quite a bit faster. Now, remember that Table has the
attribute HoldAll, so that it shouldn't evaluate the iterators before doing
the Table operation, which means that Table shouldn't be able to figure out
that it's result will be greater than 250 elements long, and so Table
shouldn't use packed arrays. This basically explains the differences in
timing. However, this explanation isn't complete, since you do see an
improvement in timing when you evaluate the second iterator. Perhaps Table
does evaluate it's first iterator despite the HoldAll attribute.

Carl Woll
Physics Dept
U of Washington

"Mariusz Jankowski" <mjkcc at usm.maine.edu> wrote in message
news:bi18ce$afl$1 at smc.vnet.net...
> Dear Mathematica Users,
>
> Can someone explain the timing difference between the following two code
> samples. I am guessing it has to do with the auto-compiler, but even if I
am
> correct, I would like to know more.
>
> Slow version:
>
> n=m=100;
> Timing[Do[Table[1,{i,1,n},{j,1,m}],{1000}];]
>
>
>
> Fast version:
>
> n=m=100;
>
> Timing[Do[Table[1,{i,1,n},Evaluate[{j,1,m}]],{1000}];]
>
> which is as fast as
>
> Timing[Do[Table[1,{i,1,100},{j,1,100}]],{1000}];]
>
> I also noticed that only the outermost iterator needs to be wrapped in
> Evaluate. Why(?)
>
>
>
> Thanks, Mariusz
>
>
>



  • Prev by Date: SoBig Virus and the Mathematica mailing list and newsgroup
  • Next by Date: Re: Are points co-planar in (numDimensions-1)?
  • Previous by thread: Timing of Table
  • Next by thread: Re: Timing of Table