Python example: possible speedup?

Tim Peters tim_one at email.msn.com
Wed Sep 8 20:57:46 EDT 1999


[Hrvoje Niksic, writes a pretty text-crunching program in Python
 that's-- horrors! --slower than a Perl workalike]

[Robert Vollmert, among others, does various irksome things to
 speed it up, and remarks ...]
> The main speed advantage seems to be that the files aren't
> processed line by line, which is of course very memory consuming.

This probably bears repetition about once a month <wink>:  Python does
line-at-a-time input on top of the platform's stdio package.  On the popular
platforms, Perl does line-at-a-time input by breaking into the platform's
stdio package, peeking and poking C FILE structs directly in
platform-specific ways.  This can give Perl a huge speed advantage on
line-at-a-time input; indeed, on Windows, Perl does line-at-a-time input
faster than pure optimized C/C++ code using Microsoft's fgets, and about 3x
faster than Python under Win95.  Perl's speed advantage here is directly
proportional to the stupidity of the platform's stdio implementation ("read
a line from a file?  who on earth would want to do that?" <wink>).

eschew-files-embrace-3d-buttons-ly y'rs  - tim






More information about the Python-list mailing list