Created
August 3, 2020 10:34
-
-
Save kshirsagarsiddharth/b22249d66be190a73454a7ea1d794bac to your computer and use it in GitHub Desktop.
comparision
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
| # for normal file | |
| import os | |
| import time | |
| start_time = time.time() | |
| with open("example_file.pdf","rb") as f: | |
| buffer_size = 64 | |
| retract_size = -32 | |
| while True: | |
| f.seek(buffer_size,os.SEEK_CUR) | |
| pass | |
| f.seek(retract_size,os.SEEK_CUR) | |
| pass | |
| if f.tell() > 15728640: # 15MB | |
| break | |
| end_time = time.time() | |
| print(end_time - start_time) --> 2.992995500564575 | |
| # for memory mapped file | |
| import os | |
| import time | |
| import mmap | |
| start_time = time.time() | |
| with open("example_file.pdf","rb") as f: | |
| with mmap.mmap(f.fileno(),0,access=mmap.ACCESS_READ) as m: | |
| buffer_size = 64 | |
| retract_size = -32 | |
| while True: | |
| m.seek(buffer_size,os.SEEK_CUR) | |
| pass | |
| m.seek(retract_size,os.SEEK_CUR) | |
| pass | |
| if m.tell() > 15728640: # 15MB | |
| break | |
| end_time = time.time() | |
| print(end_time - start_time) --> 0.23140549659729004 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment