Speed Comparison Perl Python & C

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Tue Mar 2 20:06:49 EST 2004


> From: ciw42
> 
> Compiled optimised code will (should) always be significantly 
> faster than
> interpreted code, but you lose all of the benefits of using a 
> language such
> as Python in the process, so it's all rather pointless 
> comparing languages
> in this way.

Of course, it's possible to create some *really* bad code in Python. I've just spent a day finding and fixing an algorithm which turned out to be O(n^3) in some legacy code (in-memory representation of an XML file for network topologies).

It was fine for the small, initial topologies that it was developed for. Unfortunately, it didn't scale overly well to the somewhat larger topologies I'm dealing with now ... like 21000 devices ...

Put it this way. One single function call was taking an hour to return. After doing some major refactoring - mainly sticking stuff into dictionaries as the file is parsed - that same function call now takes one second. Loading the file has been reduced from 3-4 hours down to 5 minutes.

Finding and fixing this bottleneck would have been a *lot* nastier in a lower-level language than Python. In Python however, the optimised algorithm is clear and understandable - in fact, moreso than the original code IMO ;)

Tim Delaney




More information about the Python-list mailing list