Created
March 19, 2011 07:15
-
-
Save gnprice/877299 to your computer and use it in GitHub Desktop.
This file contains 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
$ python -m timeit -v -s 'import bench_fnclass as b' 'b.as_fn()' | |
10 loops -> 0.000801 secs | |
100 loops -> 0.00851 secs | |
1000 loops -> 0.113 secs | |
10000 loops -> 7.75 secs | |
raw times: 7.2 7.22 7.24 | |
10000 loops, best of 3: 720 usec per loop | |
$ python -V | |
Python 2.6.6 | |
Finer-grained data: | |
$ for n in 1000 1300 1600 2100 2700 3500 4600 6000 7800 10000 13000 16000 21000; do python -m timeit -n$n -r2 -s 'import bench_fnclass as b' 'b.as_fn()'; done | |
1000 loops, best of 2: 101 usec per loop | |
1300 loops, best of 2: 112 usec per loop | |
1600 loops, best of 2: 121 usec per loop | |
2100 loops, best of 2: 136 usec per loop | |
2700 loops, best of 2: 149 usec per loop | |
3500 loops, best of 2: 167 usec per loop | |
4600 loops, best of 2: 206 usec per loop | |
6000 loops, best of 2: 289 usec per loop | |
7800 loops, best of 2: 413 usec per loop | |
10000 loops, best of 2: 733 usec per loop | |
13000 loops, best of 2: 1.18 msec per loop | |
16000 loops, best of 2: 1.64 msec per loop | |
21000 loops, best of 2: 2.33 msec per loop |
This file contains 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
def as_fn(): | |
class A(object): | |
def __init__(self, x): self.x = x | |
def f(self): return self.x | |
class B(object): | |
def __init__(self, x): self.x = x | |
def f(self): return A(self.x+'a').f() | |
class C(object): | |
def __init__(self, x): self.x = x | |
def f(self): return B(self.x+'b').f() | |
class D(object): | |
def __init__(self, x): self.x = x | |
def f(self): return C(self.x+'c').f() | |
for i in xrange(10): | |
D('d').f() | |
class AsClass(object): | |
class A(object): | |
def __init__(self, x): self.x = x | |
def f(self): return self.x | |
class B(object): | |
def __init__(self, x): self.x = x | |
def f(self): return AsClass.A(self.x+'a').f() | |
class C(object): | |
def __init__(self, x): self.x = x | |
def f(self): return AsClass.B(self.x+'b').f() | |
class D(object): | |
def __init__(self, x): self.x = x | |
def f(self): return AsClass.C(self.x+'c').f() | |
@staticmethod | |
def go(): | |
for i in xrange(10): | |
AsClass.D('d').f() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment