Created
April 15, 2015 23:22
-
-
Save 1st1/81402dc116aa322067c9 to your computer and use it in GitHub Desktop.
async bench
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
import sys | |
import time | |
# import sys | |
# sys.set_generator_wrapper(lambda x: x) | |
def binary(n): | |
if n <= 0: | |
return 1 | |
l = yield from binary(n - 1) | |
r = yield from binary(n - 1) | |
return l + 1 + r | |
def timeit(gen, depth, repeat): | |
t0 = time.time() | |
for _ in range(repeat): | |
list(binary(depth)) | |
t1 = time.time() | |
print('%s(%d) * %d: total %.3f' % | |
(gen.__name__, depth, repeat, t1-t0)) | |
timeit(binary, depth=19, repeat=30) | |
# async branch; with wrapper patch (no wrapper) | |
# | |
# binary(19) * 30: total 13.554 | |
# binary(19) * 30: total 13.552 | |
# binary(19) * 30: total 13.698 | |
# binary(19) * 30: total 13.632 | |
# async branch; with wrapper patch (identity func) | |
# | |
# binary(19) * 30: total 17.866 | |
# binary(19) * 30: total 17.817 | |
# binary(19) * 30: total 17.999 | |
# binary(19) * 30: total 17.645 | |
# async branch | |
# | |
# binary(19) * 30: total 13.446 | |
# binary(19) * 30: total 13.613 | |
# binary(19) * 30: total 13.513 | |
# binary(19) * 30: total 13.536 | |
# master branch | |
# | |
# binary(19) * 30: total 13.164 | |
# binary(19) * 30: total 13.201 | |
# binary(19) * 30: total 13.314 | |
# binary(19) * 30: total 13.385 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment