cost of closure

tags: learning programming

content

comparing two functions:

  • with closure
def outer_func():
	def inner_func():
		pass
	return inner_func()
  • without closure
def func1():
	return _func1()
def _func1():
	pass
  • with closure
    • all logic is in one code block, self-contained
    • it’s creating a new function object inner_func every time outer_func is called, there’s a runtime cost

up

down

reference