-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jorge Godoy schrieb: > Dan Pascu <[EMAIL PROTECTED]> writes: > >> That is a common myth. People should test things themselves instead >> of believing everything that is written on the net. > > There were recent optimizations on that area IIRC. I believe that the > statement is true with Python 2.X where X < 4.
I just did some quick tests: As of Python 2.4 string-concat using '+' seams to be faster than the '%' operator. Sorry, no Python 2.3 at hand to check it against. - -------------- s = "foo" s += "bar" >> 0.400207996368 - -------------- s = "foo" s = s + "bar" >> 0.398325920105 - -------------- s = "foo" s = ''.join((s, "bar")) >> 0.929105997086 - -------------- s = "foo" s = "%sbar" % s >> 0.675987958908 - -------------- s = "foo" s += "bar" s += "baz" >> 0.716789007187 - -------------- s = "foo" + "bar" + "baz" >> 0.655229091644 - -------------- s = ''.join(("foo", "bar", 'baz')) >> 0.883416175842 - -------------- s = '%s%s%s' % ("foo", "bar", 'baz') >> 0.902904987335 - -------------- s = "foo" s = "%sbar" % s >> 0.682669878006 Code: cases = [ ''' s = "foo" s += "bar" ''', ''' s = "foo" s = s + "bar" ''', ''' s = "foo" s = ''.join((s, "bar")) ''', ''' s = "foo" s = "%sbar" % s ''', ''' s = "foo" s += "bar" s += "baz" ''', ''' s = "foo" + "bar" + "baz" ''', ''' s = ''.join(("foo", "bar", 'baz')) ''', ''' s = '%s%s%s' % ("foo", "bar", 'baz') ''', ''' s = "foo" s = "%sbar" % s ''' ] from timeit import Timer for c in cases: t = Timer(stmt=c) print '--------------', print c, print '>>', t.timeit() - -- Sch?nen Gru? - Regards Hartmut Goebel | Hartmut Goebel | IT-Security -- effizient | | [EMAIL PROTECTED] | www.goebel-consult.de | -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org iQEVAwUBRT4Oa8zajR0mSa83AQLt3Qf/aVd65VmjfiL7Hf8K002r4KHvq/1HlSx1 2AunaVJ7ozdaSmQ9W06Q8cQ2av5zw8ULcfYzxdw6lMeMfeVmFHg4RR1asd+rF/He kQvdBfTlf6VRfEgVuCU7wnP63fhTqbwYKYhzWI4A7kbGjsPnS8/ii9Sk6Z053KCu 683xZV/7uSmvfw8Prp92ZDgQ6Ttm4EPeYBDR99MIaq6FHfJVxsZxakKKe8dhVrgK DF188oEQ/4JdOA57Pq3QPGVTBQvIMEYM6qkh15cJrvOF2Yb7fVRUDCCSjhCdn/18 XYiFjLt0Hhx0ulTnk5UtQA7i9DL7+Cl89xWzwKHszDYACGUMiO8LHw== =vCo6 -----END PGP SIGNATURE----- ------------------------------------------------------------------------- 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 sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss