#!/usr/bin/python3 # -*- coding: utf-8 -*- """Measure Python (CPython, 2 or 3) function-call overhead. It gives a measure consistently about 200–230 ns on my laptop in Python 3 and more like 190 ns in Python 2. """ from time import time def bar(): pass def foo(): bar() n = int(1e7) if __name__ == '__main__': start = time() for i in range(n): bar() onefunc = time() - start start = time() for i in range(n): foo() twofunc = time() - start print((twofunc-onefunc)/n, "seconds per niladic function call and return")