Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Vectorization

  • To: mathgroup at
  • Subject: [mg60671] Re: [mg60623] Vectorization
  • From: Zhengji Li < at>
  • Date: Fri, 23 Sep 2005 04:20:41 -0400 (EDT)
  • References: <>
  • Reply-to: Zhengji Li < at>
  • Sender: owner-wri-mathgroup at


That's because the construction of the LONG complex vector uses far
more time than long real vector.

To simplify the matter, just throw Sin away:
Table[I Random[], {1000000}] // Timing // First
I Table[I Random[], {1000000}] // Timing // First
1.983 Second, 3.786 Second.

The frist one is the contruction ONE complex vector, while in the
second one another vector is contructed due to the I * {...}
operation. And 3.786 Second is about 2 * 1.983 Second.

As a comparision,
Table[Random[], {1000000}] // Timing // First
2 Table[Random[], {1000000}] // Timing // First
0.29 Second, 0.411 Second.

In your example,
Table[Sin[I Random[]],{1000000}]//Timing//First
will generate only one complex vector, while
Sin[Table[I Random[],{1000000}]]//Timing//First
will generate two complex vectors. ----- The time saved by
vectorization is less than that used by the contruction of a complex

Li Zhengji
If all you have is a hammer, everything is a nail.

  • References:
  • Prev by Date: Importing part of a WAV file
  • Next by Date: Re: Vectorization
  • Previous by thread: Vectorization
  • Next by thread: Re: Vectorization