Skip to content

Instantly share code, notes, and snippets.

@daemianmack
Created August 13, 2012 14:43
Show Gist options
  • Save daemianmack/3341350 to your computer and use it in GitHub Desktop.
Save daemianmack/3341350 to your computer and use it in GitHub Desktop.
class Regular(object):
def __init__(self):
self.num = self.caller(5)
def not_inner(self, x):
return x * x
def caller(self, num):
return self.not_inner(num)
class Irregular(object):
def __init__(self):
self.num = self.caller(5)
def caller(self, num):
def inner(x):
return x * x
return inner(num)
>>> timeit.Timer("Regular()", "from perftest import Regular").timeit()
timeit.Timer("Regular()", "from perftest import Regular").timeit()
0.7716619968414307
>>> timeit.Timer("Irregular()", "from perftest import Irregular").timeit()
timeit.Timer("Irregular()", "from perftest import Irregular").timeit()
0.8771319389343262
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment