-
-
Save 1st1/1b938060fd26553f38eb to your computer and use it in GitHub Desktop.
async branch: with statement micro benchmark
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
class CM: | |
def __enter__(self): | |
global CNT1 | |
CNT1 +=1 | |
def __exit__(self, et, e, tv): | |
global CNT2 | |
CNT2 += 1 | |
import time | |
N = 10**6 | |
for _ in range(5): | |
CNT1 = CNT2 = CNT3 = 0 | |
started = time.time() | |
for _ in range(N): | |
with CM(): | |
CNT3 += 1 | |
print('%.3fs' % (time.time() - started,)) | |
assert CNT1 == CNT2 == CNT3 == N | |
""" | |
yury@ysmbp ~/dev/py/cpython-git (await *$%) $ ./python.exe t.py | |
0.727s | |
0.734s | |
0.730s | |
0.718s | |
0.717s | |
yury@ysmbp ~/dev/py/cpython-git (await *$%) $ ./python.exe t.py | |
0.719s | |
0.711s | |
0.710s | |
0.748s | |
0.805s | |
yury@ysmbp ~/dev/py/cpython-git (master $%) $ ./python.exe t.py | |
0.722s | |
0.719s | |
0.722s | |
0.732s | |
0.737s | |
yury@ysmbp ~/dev/py/cpython-git (master $%) $ ./python.exe t.py | |
0.721s | |
0.701s | |
0.698s | |
0.710s | |
0.714s | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment