Skip to content

Instantly share code, notes, and snippets.

@lozhn
Created July 12, 2020 13:55
Show Gist options
  • Save lozhn/dc003e39caedb710e296f95b7173edaf to your computer and use it in GitHub Desktop.
Save lozhn/dc003e39caedb710e296f95b7173edaf to your computer and use it in GitHub Desktop.
Timeit redis vs disk 10mb file store
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