MathGroup Archive 2007

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

Search the Archive

Re: Sierpinski's thing

  • To: mathgroup at smc.vnet.net
  • Subject: [mg76837] Re: Sierpinski's thing
  • From: "Szabolcs Horvát" <szhorvat at gmail.com>
  • Date: Mon, 28 May 2007 01:04:23 -0400 (EDT)
  • References: <f38qg9$hq4$1@smc.vnet.net> <f3bgfp$313$1@smc.vnet.net>

On 27/05/07, Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com> 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}}];
sierp[cornerPt_,sideLen_,n_]:=(sierp[cornerPt+#1*(sideLen/3),sideLen/3,n-1]&)/@pieces
sierp[cornerPt_,sideLen_,0]:=Rectangle[cornerPt,cornerPt+sideLen*{1,1}]

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

In[5]:= start=TimeUsed[];
gr
stop=TimeUsed[];
stop-start

Out[8]= 21.25

Here we turn off the anti-aliasing:

In[9]:= start=TimeUsed[];
Style[gr,Antialiasing->False]
stop=TimeUsed[];
stop-start

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)
sierp3[cornerPt_,sideLen_,0]:={Rectangle[cornerPt,cornerPt+sideLen*{1,1}]}

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

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


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

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

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

In[23]:= start=TimeUsed[];
gr2
stop=TimeUsed[];
stop-start

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
sierp4[sideLen_,0]:=Rectangle[{0,0},{sideLen,sideLen}]

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 *)

Szabolcs


  • 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