[XML-SIG] HTML<->UTF-8 'codec'? [Slightly-OT]

Schollnick, Benjamin Benjamin.Schollnick@usa.xerox.com
Sat, 20 Oct 2001 10:08:55 -0400


I've got a perfect example of that....

I just wrote a quick RPG utility to act as a dice roller (via the random
module)....

I created a audit trail, by using:

results = results + "\nCurrent Dice roll = " + str(dice_roll)

And while being reasonably fast, it quickly slowed down after 1000 or so
rolls... (10,000 took roughly 1-2 minutes to process) [That's assuming I
recall correctly, it was certainly over 40 seconds...] .

When I converted the results audit trail to a list:

results.insert (1, "Current Dice Roll ...")

A 10,000 roll sequence only takes roughly 1.5 seconds....

There's other things going on of course....But for strings that you
are appending data to, it's a safe better to use a list....(for large
groups of data).

It's quite simple to:

string.join(list_variable) 

To produce a string result from the list...

			- Benjamin

-----Original Message-----
From: Thomas B. Passin [mailto:tpassin@home.com]
Sent: Saturday, October 20, 2001 10:06 AM
To: xml-sig@python.org
Subject: Re: [XML-SIG] HTML<->UTF-8 'codec'?


[Martin v. Loewis]

>
> Even with these improvements, building up a string by adding tail
> segments requires repeated copying of the string head. This can be
> avoided with a pre-allocated list L, using string.join(L,"") when
> done.
>

We had a thread on this a while ago (I thinkit was this year, but maybe it
was last).  When the string is small it makes no noticeable difference, but
as the string gets larger the speedup of using a list can be dramatic, even
more than an order of magnitude.  Anything more than a few KB for the final
string would probably benefit from the list approach - especially when you
add to the string a character at a time.

Cheers,

Tom P


_______________________________________________
XML-SIG maillist  -  XML-SIG@python.org
http://mail.python.org/mailman/listinfo/xml-sig