MathGroup Archive 2013

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

Search the Archive

Timing puzzle

  • To: mathgroup at
  • Subject: [mg130424] Timing puzzle
  • From: at
  • Date: Wed, 10 Apr 2013 00:53:07 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:

I am writing a graphics package that often creates objects with thousands of polygons, possibly up to 10^5. Out of curiosity I tested 5 ways of dynamically creating a plot list, using AppendTo, Append, Join, etc., and did the following timing test of 5 ways to do it:

ClearAll[poly,p,n]; poly={}; n00;
p[arg_]:= {mygraphic[mycolor[Random[],Random[],Random[]]],
ClearAll[poly]; poly={};
ClearAll[poly]; poly={};
ClearAll[poly]; poly={};
ClearAll[poly]; poly=Table[0,{n}];

Running with n00 on a MacPro under Mac OSX 10.6.8 gives these times:

0.911327 Second
0.891656 Second
0.927267 Second
0.504454 Second
0.009575 Second

Question: why is the last method much faster?  I thought that appending an object to a list should take about the same time as storing an array entry.  When I worked with linked lists several decades ago (using assembly code on a CDC 7600) all I had to do is retrieve the object address,  manipulate registers, store in a pointer array, and presto! it was done.

  • Prev by Date: Re: How can I force mathematica to collect a symbol from a polynomial
  • Next by Date: Re: rayshade POV Export help asked
  • Previous by thread: Re: Reading a file in reverse order --- How?
  • Next by thread: Re: Timing puzzle