MathGroup Archive 2011

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

Search the Archive

unexpected Timing results

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115826] unexpected Timing results
  • From: gleam at flashmail.com
  • Date: Fri, 21 Jan 2011 04:35:57 -0500 (EST)

I experienced a couple of rather unexpected timing results today that 
I am hoping can be explained to me.

  In Mathematica 7.0.1:

ragged = RandomInteger[1*^6, #] &~Array~1000;

Do[PadLeft[ragged], {50}] // Timing
Do[PadLeft[ragged, {1000, 1000}], {50}] // Timing
Do[PadLeft[#, 1000] & /@ ragged, {50}] // Timing

{4.422, Null}
{4.406, Null}
{0.344, Null}

This difference I did not anticipate.  I suppose this has something 
to do with packed arrays, but I do not understand why the upper two 
forms do not handle the task at least as well as the third one.  I 
expected a function that can be applied at the top level to be faster 
that way, than when manually mapped.

Now, truly baffling to me is this:

padded = PadLeft[#, 1000] & /@ ragged;

Do[Accumulate[padded], {800}] // Timing
Do[Map[Accumulate, padded, {0}], {800}] // Timing

{5.109, Null}
{4.188, Null}

Should not these forms be identical, other than a slight overhead for 
the Map function?  How can Map[f, x, {0}] be faster than f[x] ?  I 
was sure this timing was a fluke, so I restarted Mathematica and 
repeated it several times, and the result held.

Paul 




  • Prev by Date: Re: Simple n-tuple problem - with no simple solution
  • Next by Date: Re: Simple n-tuple problem - with no simple solution
  • Previous by thread: Re: problem with LessEqual::nord:
  • Next by thread: Re: unexpected Timing results