On 10/24/06, Dan Pascu <[EMAIL PROTECTED]> wrote:
> If this was ever true, it must have been with _very_ old python versions
> (if ever). I have my doubts this was ever true as even in C strcpy and
> strcat are a number of times faster than sprintf, and the number and
> complexity of the operations a printf like operator needs to do, far
> outweight a simple string concatenation.

Since Python string objects are immutable, a new instance of the
object has to be created, which can become expensive, if the strings
become quite long.  A performant way to concatenate Strings is to add
the strings to a list, and join the list at the end.  Executing the
following script on my computer using Python 2.4 for 100000 iterations
takes 0.063 vs. 0.062 seconds, so no big difference, but when
performing 1000000 iterations the difference becomes quite large:
6.125 vs. 0.532 seconds, so joining the list is more than 10 times
faster.  Things get worse for string concatenation with larger
strings.


import time

count = 1000000

a = ''
start = time.time()
for i in range( count ):
    a += 'hello'
print time.time() - start

b = []
start = time.time()
for i in range( count ):
    b.append( 'hello' )
''.join( b )
print time.time() - start

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to