[Python-ideas] multiple objects handling

海韵 lyricconch at gmail.com
Wed Aug 17 02:46:31 CEST 2011


= =!, try this:

@vars
class _DispatchTable():
     def add(...):
           pass
     def sub(...):
           pass

def process(..., Switch=_DispatchTable):
     ...
     val = Switch[action](...)
     ...

2011/8/13 Nick Coghlan <ncoghlan at gmail.com>:
> On Sat, Aug 13, 2011 at 8:18 AM, Peter V. Saveliev <peet at altlinux.ru> wrote:
>>> Have you actually profiled the performance of your program? I would
>>> guess that the time spent dispatching through a dictionary is dwarfed by
>>> the time spent constructing those event objects and the ultimate
>>> processing of them.
>>
>> You're right, but having really huge stream of packets I try to minimize
>> any overhead — using C modules, ctypes library and so on. But I hope to
>> save high-level logic in Python, and before to reject a chance to speed
>> up parsing, I asked for some alternatives and contras. I believe that
>> method calls here are unnecessary while the «if» statements tree makes
>> the code hard to support.
>
> This kind of logic micro-optimisation is best handled by a JIT
> compiler rather than messing with the language definition and asking
> people to do it by hand. I suggest running your application on PyPy
> and seeing what kind of speed up you get.
>
> Cheers,
> Nick.
>
> --
> Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



More information about the Python-ideas mailing list