MathGroup Archive 2007

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

Search the Archive

Re: Sierpinski's thing

On 27/05/07, Jean-Marc Gulliet <jeanmarc.gulliet at> wrote:
> For what is worth, I have made some speed tests of your code on version
> 5.2 and 6.0. The speed difference is striking in this case. The culprit
> seems to be the rendering engine in v6. As a summary,
> ------------------------------------------------------
>       V5.2        !                V6.0
>                   ! Native Engine    ! Legacy Engine 5.2*
> ------------------------------------------------------
> Create ! Display ! Create ! Display ! Create ! Display
> 0.938  ! 0.187   ! 1.703  ! 24.765  ! 0.954  ! 0.234
> ------------------------------------------------------

It seems that it is not even the rendering itself that takes so long.
With anti-aliasing turned off, the performance does not improve
noticeably. But when the graphics have already been displayed,
resizing is quite fast.

The graphics are probably converted to some other representation
before they are displayed, and the conversion takes a long time.

I experimented a bit more with this:

sierp[ ] is the original function, display time is: -- 21.2 sec
sierp3[ ] is the same as sierp[ ], but produces a flat list. -- 18.8 sec
sierp2[ ] uses Translate[ ] to shift the pieces. -- 75 sec.
sierp4[ ] uses trans[ ] (defined below) to simulate the effect of
Translate[ ]. Creation time is 2.4 sec, so there is no excuse for
sierp2[ ]'s output to be rendered so slowly. It's probably better to
avoid Translate[ ].

I hope that the design of the rendering system allows for some
optimisation here and we shall see a huge improvement in the next
version. This is an unacceptable performance regression from 5.2.

In[1]:= pieces=Complement[Join@@Table[{i,j},{i,0,2},{j,0,2}],{{1,1}}];

In[4]:= gr=Graphics[sierp[{0,0},1,5]];

In[5]:= start=TimeUsed[];

Out[8]= 21.25

Here we turn off the anti-aliasing:

In[9]:= start=TimeUsed[];

Out[12]= 21.203

This version producees a flat list of graphics primitives. It seems
that the processing takes a bit less time in this case.

In[13]:= sierp3[cornerPt_,sideLen_,n_]:=Join@@((sierp3[cornerPt+#1*(sideLen/3),sideLen/3,n-1]&)/@pieces)

In[15]:= gr3=Graphics[sierp3[{0,0},1,5]];

In[16]:= start=TimeUsed[];
Out[19]= 18.797

With Translate[ ], it is awfully slow ...

In[20]:= sierp2[sideLen_,n_]:=Translate[sierp2[sideLen/3,n-1],sideLen/3#]&/@pieces

In[22]:= gr2=Graphics[sierp2[1,5]];

In[23]:= start=TimeUsed[];

Out[26]= 74.781

Now let's use our own version of Translate[], to see if it is really
necessary for Translate[] to be so slow!

In[27]:= sierp4[sideLen_,n_]:=trans[sierp4[sideLen/3,n-1],sideLen/3#]&/@pieces

In[29]:= trans[elem_,vec_]:=elem/.Rectangle[a_,b_]:>Rectangle[a+vec,b+vec]

In[30]:= Timing[gr4=Graphics[sierp4[1,5]];]

Out[9]= {2.359,Null} (* creation time *)


  • Prev by Date: Re: Re: Re: What to do in v. 6 in place of Miscellaneous`RealOnly
  • Next by Date: Re: Re: Stopping Automatic Animation in v6
  • Previous by thread: Re: Sierpinski's thing
  • Next by thread: Re: Sierpinski's thing