<div dir="ltr">I use inspect.stack() to extract some info, such as file name, function name and line number, for the sake of logging (home brew logger).<br>I tested to see how much time it takes to execute the command:<br>
<br>Python 2.4.3 (#1, Jan 21 2009, 01:11:33) <br>[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2<br>Type "help", "copyright", "credits" or "license" for more information.<br>>>> import timeit<br>
>>> t = timeit.Timer('inspect.stack()', 'import inspect')<br>>>> t.repeat(3,1000)<br>[0.28500604629516602, 0.28315305709838867, 0.29169297218322754]<br>>>> <br><br>About 280uSec per call.<br>
<br>If I log 1000 times per seconds than I get to spend 28% of the process time on inspect.stack()<br>Is there a better/quicker way of retrieving the same info?<br><br>Thanks,<br>--doron<br></div>