Created
August 13, 2012 14:43
-
-
Save daemianmack/3341350 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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