Skip to content

Instantly share code, notes, and snippets.

@maxiberta
Created February 24, 2017 21:50
Show Gist options
  • Save maxiberta/3825652ab9b200970cc2156955d35f3f to your computer and use it in GitHub Desktop.
Save maxiberta/3825652ab9b200970cc2156955d35f3f to your computer and use it in GitHub Desktop.
How long does it take Python to write lots of data to file on disk?
"""
$ python3 writebench.py
Wrote 4768.42 MB in 2.30 secs
"""
import os
import tempfile
import time
t0 = time.time()
with tempfile.NamedTemporaryFile(delete=False) as f:
for i in range(1000 * 100):
f.write(b'x' * i + b'\n')
size = os.path.getsize(f.name) / 1024 / 1024
elapsed = time.time() - t0
print('Wrote {0:.2f} MB in {1:.2f} secs'.format(size, elapsed))
os.remove(f.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment