, , timeit :
def a():
pass
class A(object):
pass
class B(object):
def __init__(self):
pass
class NOPType(type):
pass
class C(object):
__metaclass__ = NOPType
def __init__(self):
pass
class D(object):
def __new__(cls, *args, **kwargs):
return super(D, cls).__new__(cls)
def __init__(self):
pass
class E(A):
def __init__(self):
super(E, self).__init__()
:
$ python -m timeit -s "import tst" "tst.a()"
10000000 loops, best of 3: 0.149 usec per loop
$ python -m timeit -s "import tst" "tst.A()"
10000000 loops, best of 3: 0.169 usec per loop
$ python -m timeit -s "import tst" "tst.B()"
1000000 loops, best of 3: 0.384 usec per loop
$ python -m timeit -s "import tst" "tst.C()"
1000000 loops, best of 3: 0.397 usec per loop
$ python -m timeit -s "import tst" "tst.D()"
1000000 loops, best of 3: 1.09 usec per loop
$ python -m timeit -s "import tst" "tst.E()"
1000000 loops, best of 3: 0.827 usec per loop
, :
- 1,1 .
__init__ 2.6- - no-op - , 2.7.
__new__, 7.3- 5,6
2, super .
, python python, CPython 2.7.