Code that ought to run fast, but can't due to Python limitations.

Stefan Behnel stefan_ml at behnel.de
Sun Jul 5 05:04:33 EDT 2009


John Nagle wrote:
> Paul Rubin wrote:
>> John Nagle <nagle at animats.com> writes:
>>> Python doesn't have a "switch" or "case" statement, and when
>>> you need a state machine with many states, that makes for painful,
>>> slow code.  ...
>>> There's a comment in the code that it would be useful
>>> to run a few billion lines of HTML through an instrumented version
>>> of the parser to decide in which order the IF statements should be
>>> executed.  You shouldn't have to do that.
>>
>> In that particular program it would probably be better to change those
>> if/elif/elif/else constructs to dictionary lookups.  I see the program
>> already does that for some large tables.
> 
>    A dictionary lookup (actually, several of them) for every
> input character is rather expensive.

Did you implement this and prove your claim in benchmarks? Taking a look at
the current implementation, I'm pretty sure a dict-based implementation
would outrun it in your first try.

Stefan



More information about the Python-list mailing list