MathGroup Archive 2005

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

Search the Archive

Re: Vectorization


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.

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