I need to detect whether a function is an empty definition or not. It can be like:
def foo():
pass
or like:
def foo(i, *arg
Why would you do that? It looks like bad design. I would bet you wouldn't make anything faster.
python -m timeit -s'def a(): pass' -s'def b(): pass' 'if a.__code__.co_code == b.__code__.co_code: pass'
1000000 loops, best of 3: 0.293 usec per loop
python -m timeit -s 'def a(): pass' -s 'def b(): pass' 'a()'
10000000 loops, best of 3: 0.0941 usec per loop
It seems like it is magnitude slower to compare than to just do call, because there were 10 times more loops in the latter timeit. The equals operator actually is surely calls a.code.co_code.eq. So you are just making things slower.