[Bf-python] svg2obj script.

Martin Poirier theeth at yahoo.com
Wed Mar 28 18:15:51 CEST 2007


--- Campbell Barton <cbarton at metavr.com> wrote:

> jmsoler at free.fr wrote:
> > Selon Martin Poirier <theeth at yahoo.com>:
> > 
> > 
> >> The part that removes redundant spaces can be
> factored
> >> out too.
> >>
> >> def remSpaces(txt):
> >>     t1 = txt
> >>     t2 = txt.replace("  ", " ")
> >>     while len(t1) != len(t2):
> >>         t1 = t2
> >>         t2 = t1.replace("  ", " ")
> >>
> > 
> > 
> > 
> > And you really believe that the code that you
> suggest above is
> > simpler and faster than :
> >    while '  ' in t2: t2=t2.replace('  ',' ')

I'm glad you asked, the answer is: yes, but not by
much and not always.

If you cared to test (with 2.4), it goes like this:

F1: loop with len
F2: loop with find (your original version, I might
add)
F3: loop with __containts__ (in)

Comparing execution time.

With short strings:

F3 < F1 < F2

(Here, F1 is 5% slower than F3)

With longer strings (I used the actual code of the
test script as input with some spaces added):

F1 < F2 < F3

(Here, F3 is 10% slower than F1)

However, for that change, I wasn't so much advocating
speed (those three versions are fast enough, taking
less than .2 ms on the large strings test) than
separation of reusable functions.

> Of course its faster, one less lookup per cycle,
> 
> while '  ' in t2: is a lookup
> 
> Where martins example just checks that theres always
> a change in the 
> string size.

While mine doesn't do the extra lookup each run of the
loop, it does run one extra replace at the end though
(the last one before detecting no changes).

> The error happened for the 2 svg files I tried to
> import. both fairly 
> simple and from inkscape.

So, I can assume you sent those to Jean-Michel
already?

Martin


 
____________________________________________________________________________________
8:00? 8:25? 8:40? Find a flick in no time 
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news



More information about the Bf-python mailing list