Created
February 24, 2017 21:50
-
-
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?
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
""" | |
$ 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