Code that ought to run fast, but can't due to Python limitations.
Paul Rubin
http
Sun Jul 5 05:38:54 EDT 2009
Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> writes:
> Yes, I'm aware of that, but that's not what John's code is doing -- he's
> doing a series of if expr ... elif expr tests. I don't think a case
> statement can do much to optimize that.
The series of tests is written that way because there is no case
statement available. It is essentially switching on a bunch of
character constants and then doing some additional tests in each
branch.
It could be that using ord(c) as an index into a list of functions
might be faster than a dict lookup on c to get a function. I think
John is hoping to avoid a function call and instead get an indexed
jump within the Python bytecode for the big function.
More information about the Python-list
mailing list