Created
November 19, 2015 03:52
-
-
Save markrwilliams/dea42ec7914e4d54fb23 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
from threading import RLock | |
class T(object): | |
def __init__(self): | |
self.lock = RLock() | |
def _meth(self): | |
pass | |
@staticmethod | |
def _smeth(): | |
pass | |
def nometh(self): | |
with self.lock: | |
pass | |
def instmeth(self): | |
with self.lock: | |
self._meth() | |
def statmeth(self): | |
with self.lock: | |
self._smeth() | |
t = T() |
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
mrw@hammal:/tmp$ python -m timeit -s 'from locktest import t' 't.nometh()' | |
100000 loops, best of 3: 1.84 usec per loop | |
mrw@hammal:/tmp$ python -m timeit -s 'from locktest import t' 't.nometh()' | |
100000 loops, best of 3: 1.87 usec per loop | |
mrw@hammal:/tmp$ python -m timeit -s 'from locktest import t' 't.nometh()' | |
100000 loops, best of 3: 1.81 usec per loop | |
mrw@hammal:/tmp$ python -m timeit -s 'from locktest import t' 't.instmeth()' | |
100000 loops, best of 3: 1.92 usec per loop | |
mrw@hammal:/tmp$ python -m timeit -s 'from locktest import t' 't.instmeth()' | |
100000 loops, best of 3: 2.05 usec per loop | |
mrw@hammal:/tmp$ python -m timeit -s 'from locktest import t' 't.instmeth()' | |
1000000 loops, best of 3: 1.96 usec per loop | |
mrw@hammal:/tmp$ python -m timeit -s 'from locktest import t' 't.statmeth()' | |
100000 loops, best of 3: 1.99 usec per loop | |
mrw@hammal:/tmp$ python -m timeit -s 'from locktest import t' 't.statmeth()' | |
100000 loops, best of 3: 2.01 usec per loop | |
mrw@hammal:/tmp$ python -m timeit -s 'from locktest import t' 't.statmeth()' | |
100000 loops, best of 3: 1.98 usec per loop | |
mrw@hammal:/tmp$ python -m timeit -s 'from locktest import t' 't.statmeth()' | |
100000 loops, best of 3: 1.99 usec per loop | |
mrw@hammal:/tmp$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment