food for thought as noticed by a coworker who has been profiling some hot code to optimize a library...<br><br>If a function does not have a return statement we return None. Ironically this makes the foo2 function below faster than the bar2 function at least as measured using bytecode size:<br>
<br>Python 2.6.2 (r262:71600, Jul 24 2009, 17:29:21) <br>[GCC 4.2.2] on linux2<br>Type "help", "copyright", "credits" or "license" for more information.<br>>>> import dis<br>
>>> def foo(x):<br>... y = x()<br>... return y<br>... <br>>>> def foo2(x):<br>... return x()<br>... <br>>>> def bar(x):<br>... y = x()<br>... <br>>>> def bar2(x):<br>... x()<br>
... <br>>>> dis.dis(foo)<br> 2 0 LOAD_FAST 0 (x)<br> 3 CALL_FUNCTION 0<br> 6 STORE_FAST 1 (y)<br><br> 3 9 LOAD_FAST 1 (y)<br>
12 RETURN_VALUE <br>>>> dis.dis(foo2)<br> 2 0 LOAD_FAST 0 (x)<br> 3 CALL_FUNCTION 0<br> 6 RETURN_VALUE <br>>>> dis.dis(bar)<br>
2 0 LOAD_FAST 0 (x)<br> 3 CALL_FUNCTION 0<br> 6 STORE_FAST 1 (y)<br> 9 LOAD_CONST 0 (None)<br> 12 RETURN_VALUE <br>
>>> dis.dis(bar2)<br> 2 0 LOAD_FAST 0 (x)<br> 3 CALL_FUNCTION 0<br> 6 POP_TOP <br> 7 LOAD_CONST 0 (None)<br> 10 RETURN_VALUE <br>
<br>