[MERGE] TreeTransform avoids many renames when constructing trees
Aaron Bentley
aaron.bentley at utoronto.ca
Tue Jun 5 17:23:20 BST 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
John Arbash Meinel wrote:
> What I found was that for long (100k entry) lists that:
>
> foo = sorted([x for x in something])
>
> is slightly (<10%) faster than:
>
> foo = sorted(x for x in something)
>
> My only guess is that it can pre-allocate somehow. The tradeoff, however, is
> that you have another copy of the data in memory. (in the temporary list).
It's also possible that it's because using a generator expression is
slower than using a list comprehension. That seems perfectly reasonable
to me. Iterators are not orders of magnitude faster than function calls.
> can do the same thing at effectively the same speed but without creating an
> intermediate list.
>
> I also just found that doing:
>
> x = [n for n in y]
> x.sort()
>
> isn't strictly slower than
> x = sorted([n for n in y])
Well, that's an odd result.
Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGZY340F+nu1YWqI0RAqqwAJ9lUEo7VncbRxbRk1sLGm4sRdY5HQCaA6Vd
lPWL/E7qyz0XbY1o0b8pyfM=
=63YW
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list