Some optimization tale
stephan.diehlNOSPAM at gmx.net
Tue Dec 30 15:44:38 CET 2003
Christos TZOTZIOY Georgiou wrote:
> On Mon, 29 Dec 2003 17:08:39 +0100, rumours say that Stephan Diehl
> <stephan.diehlNOSPAM at gmx.net> might have written:
>>> You might also want to read:
>>Terry's solution is much faster (at least on my test set) and, as an
>>additional benefit, is the easiest to understand.
> Yep, I believe clarity is essential in the library (and that is why my
> patch was obviously not accepted :) Actually IIRC (it's been a long
> since) that code never compares more than once prefixes that have been
> found equal and does not create slices (used buffer() and then switched
> to startswith() for future compatibility), that is why it's a little
> complicated. The main loop runs math.ceil(math.log(N,2)) times, where N
> is min([len(x) for x in argument_list]).
> Anyway, perhaps Terry or you should update the SF patch so that
> os.path.commonprefix becomes faster... the point is to benefit the whole
> Python community, right? :)
In principle, yes :-)
I'm not too sure if commonprefix is used that often and in a way that would
really be worth the effort to patch the existing code. (I guess, if there
had been a real need, it would have been done already a long time ago).
Another thing is that the speed improvement would be largely due to using C
implemented functions instead of pure Python code (o.k., the lines are
blury here). In order to understand what's going on, one needs to know what
kind of functions are C implemented and why, in that particular case, it is
a good idea, to use them.
More information about the Python-list