Following up on this answer: https://stackoverflow.com/a/17366561/1982118
On my macbook pro 2015 (2.8 GHz Intel Core i7) with python 3.6, I get:
python3 -m timeit -s 'import inspect' 'inspect.currentframe().f_code.co_name'
>>> 1000000 loops, best of 3: 0.428 usec per loop
python3 -m timeit -s 'import sys' 'sys._getframe().f_code.co_name'
>>> 10000000 loops, best of 3: 0.114 usec per loop
using sys._getframe() is 4 times faster than inspect.currentframe().
How come?