""" Original: f(): [1000 calls] 8240.0 B per call f2(): [1000 calls] 8208.0 B per call Patch: f(): [1000 calls] 8304.0 B per call (+64 B) f2(): [1000 calls] 8304.0 B per call (+96 B) """ import _testcapi import functools import sys def f(n): if n > 1: return p(n - 1) else: return _testcapi.stack_pointer() p = functools.partial(f) def f2(ignored, n): if n > 1: return p2(n - 1) else: return _testcapi.stack_pointer() p2 = functools.partial(f2, "ignored") sys.setrecursionlimit(100_000) def test(func, ignored=None): n = 1000 start = _testcapi.stack_pointer() stop = func(n) call = abs(stop - start) / n print("[%s calls] %.1f B per call" % (n, call)) print("f(): ", end='') test(p) print("f2(): ", end='') test(p2, "ignored")