bad generator performance

Johannes Ahl-mann softpro at gmx.net
Sun Feb 6 10:58:31 EST 2005


> You don't really give the complete story so it's hard to tell what
> exactly is going on. For example, I would assume the recursion is
> calling the same method (i.e., depthFirstIterator1 or
> depthFirstIterator2), but then you posted separate timing information
> for a "recursive helper function" so I'm not so sure. Also there is not
> much of a hint as to the nature of your data.

yeah, sorry. i'm not myself lately ;-))
forget about the helper function, that was nonsense! i used a helper
function to build a huge tree as test data, but that is the same
function for both cases!

the program is supposed to manage bookmarks and i thought it would be a
good idea to represent the bookmarks as a tree (with folders as internal
nodes and bookmarks as leaves).
so, a tree is never going to hold more than say 2000 nodes and is going
to be rather wide than deep!

> In my testing (on Python 2.3.4 on
> Windows XP), the generator version takes about 1/4 of the time that the
> list version takes. If both versions call the list version of the method
> recursively (i.e., you're only getting the benefit of the generator at
> the top level of the recursion), the generator version is still about
> 20% faster.
>
> Timing differences could potentially depend on your data also - things
> like how deep vs. wide your tree is.

thx a lot and sorry for not supplying my data type and test data!
hmm, that totally contradicts my profiling results... on my machine the
generator version is repeatedly 10 times slower than the list version as
well with python2.3 as with python2.4.
i don't want to spam the list with hundreds of lines of source code, so
i'll just cry a little and try to do something else than prematurely
optimising my bookmark script *gg*

thx,

Johannes



More information about the Python-list mailing list