PATCH: Speed up direct string concatenation by 20+%!

Nicko usenet at nicko.org
Wed Oct 4 22:41:51 EDT 2006


Larry Hastings wrote:
> It's *slightly* slower for two:
>
> def addTwoThings(a, b):
>     return a + b
> for i in range(10000000):
>     x = addTwoThings("aaa", "bbb")
...
> But starts paying off already, even with three:
>
> def addThreeThings(a, b, c):
>     return a + b + c
> for i in range(10000000):
>     x = addThreeThings("aaa", "bbb", "ccc")

I note that in both of those tests you didn't actually ever realise the
concatenated string.  Can you give us figures for these tests having
forced the concatenated string to be computed?

Cheers,
    Nicko




More information about the Python-list mailing list