Created
September 26, 2018 08:28
-
-
Save khvn26/a3ebf8dbb5f61eb3bc0e168ce3f2eb72 to your computer and use it in GitHub Desktop.
Python Websockets 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
websockets | 0.5335815649013966 | |
wsaccel | 17.214408515021205 | |
aiohttp | 0.7204610370099545 |
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 timeit | |
import pprint | |
INPUT = { | |
"websockets": ( | |
"""apply_mask(data, mask)""", | |
"""from websockets.speedups import apply_mask; data = b"abcdefghij" * 1024; mask = b"xyzt"; """ | |
), | |
"wsaccel": ( | |
"""masker.process(data)""", | |
"""from wsaccel.xormask import createXorMasker; data = b"abcdefghij" * 1024; masker = createXorMasker(b"xyzt"); """ | |
), | |
"aiohttp": ( | |
"""_websocket_mask(mask, data)""", | |
"""from aiohttp.http_websocket import _websocket_mask; data = b"abcdefghij" * 1024; mask = b"xyzt"; """ | |
) | |
} | |
def bench(): | |
results = {} | |
for module in INPUT: | |
result = timeit.timeit(*INPUT[module]) | |
print(f"{module}{' '*(26-len(module))}| {result}") | |
results[module] = result | |
results = {k: v for k, v in sorted(results.items(), key=lambda kv: kv[1])} | |
return results | |
if __name__ == "__main__": | |
bench() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment