Skip to content

Instantly share code, notes, and snippets.

@huseyinyilmaz
Created January 5, 2015 11:29
Show Gist options
  • Save huseyinyilmaz/af84ef34f844bd2c0a80 to your computer and use it in GitHub Desktop.
Save huseyinyilmaz/af84ef34f844bd2c0a80 to your computer and use it in GitHub Desktop.
"""
Inner function performance test
Result:
direct call = 0.335001945496
with wrapper = 0.700292110443
"""
def sum1(a, b):
return a + b
def sum2(a, b):
def wrapper():
return a + b
return wrapper()
def test1():
sum1(3, 5)
def test2():
sum2(3, 5)
if __name__ == '__main__':
import timeit
print 'direct call = %s' % timeit.timeit(test1)
print 'with wrapper = %s' % timeit.timeit(test2)
@bit2pixel
Copy link

Oh wow I it's nearly twice as slow. But what do you think about readability?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment