Hacker News new | ask | show | jobs
by pjscott 4662 days ago
I tried it with n=1000 and n=10000, and found that using xrange made it slightly faster, as did using itertools.imap, but the difference was pretty small.

(Here I'm using the stock Python 2.7.1 on a 2011 MacBook Pro.)

1 comments

using xrange made it slightly faster

That's what I would expect, since xrange works like a generator; but the internals of its implementation in CPython back when the article ran its original tests were evidently less efficient than they are now.

the difference was pretty small

I suspect that's because the strings being concatenated are really small (the largest will only be 5 bytes for n=10000). I would expect the difference to get bigger as the individual strings get larger.