3 ms·
Can you point me toward something that's alternative to switch statement for jumping opcodes. How can we speed things up?
by basic_bgnr 6y ago
Can you point me toward something that's alternative to switch statement for jumping opcodes. How can we speed things up?
- status_quo69 6y agoDo you mean a switch statement in pure-python that avoids certain opcodes, or a way to avoid executing opcodes in the main interpreter switch statement?
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- bjoli 6y agoThe other comment mentions computed Goto's. I have used those with big success when writing streaming parsers that work per-char (like a typical JSON or csv-parser). I can't remember exactly, but I think switching from a switch statement to computed gotos cut something like 10% from execution time due to better branch predictions in the CPU. That is pretty huge, considering it was a pretty small change to the char dispatch.