Method much slower than function?

sjdevnull at yahoo.com sjdevnull at yahoo.com
Thu Jun 14 14:49:53 EDT 2007


On Jun 14, 1:10 am, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> "sjdevn... at yahoo.com" <sjdevn... at yahoo.com> writes:
> > take virtually the same amount of time on my machine (2.5), and the
> > non-join version is clearer, IMO.  I'd still use join in case I wind
> > up running under an older Python, but it's probably not a big issue here.
>
> You should not rely on using 2.5

I use generator expressions and passed-in values to generators and
other features of 2.5.  Whether or not to rely on a new version is
really a judgement call based on how much time/effort/money the new
features save you vs. the cost of losing portability to older
versions.

> or even on that optimization staying in CPython.

You also shouldn't count on dicts being O(1) on lookup, or "i in
myDict" being faster than "i in myList".  A lot of quality of
implementation issues outside of the language specification have to be
considered when you're worried about running time.

Unlike fast dictionary lookup at least the += optimization in CPython
is specified in the docs (as well as noting that "".join is greatly
preferred if you're working across different versions and
implementations).

> Best is to use StringIO or something comparable.

Yes, or the join() variant.




More information about the Python-list mailing list