code style/efficiency question: text file templates

jerf at 192.255.255.255 jerf at 192.255.255.255
Sun Aug 4 00:39:10 EDT 2002


On Sat, 03 Aug 2002 19:56:20 -0500, jer wrote:
> Now, if you DO need to, don't guess. Profile the code, find the slow
> parts, and work on speeding those up. Guessing is bad because it's pretty
> much impossible to guess where your code is slow... even if you really,
> really think you know.

Oh, and you should in theory analyse the algorithms you're using to see if
there are better ones first, but given your task, the 'naive' algorithms
(which isn't insulting, that means the ones you're most likely to come up
with on a first try) are basically as good as you can do on such small
input. (It's the string operations that need optimization then, and
Python's are pretty good, as you'd expect.) So I didn't mention that.

(About the worst you could do is do something in quadratic time that
should be linear. There are some subtle ways of doing that in Python. But
with small input sizes, it doesn't matter much.)



More information about the Python-list mailing list