Created
July 12, 2020 13:55
-
-
Save lozhn/dc003e39caedb710e296f95b7173edaf to your computer and use it in GitHub Desktop.
Timeit redis vs disk 10mb file store
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 redis import Redis | |
from timeit import timeit | |
r = Redis('redis') | |
def blob(m=10): | |
return '1' * 1024 * 1024 * m | |
f10mb = blob(10) | |
def test_redis(): | |
r.set('key', f10mb) | |
x = r.get('key') | |
def test_disk(): | |
with open('test.bin', 'wb') as fp: | |
fp.write(f10mb.encode()) | |
with open('test.bin', 'rb') as fp: | |
x = fp.read() | |
def test(n=10): | |
print(f"redis") | |
print(timeit(test_redis, number=n)) | |
print(f"disk") | |
print(timeit(test_disk, number=n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment