Skip to content

Instantly share code, notes, and snippets.

@Axadiw
Created Dec 15, 2020
Embed
What would you like to do?
#!/usr/bin/env python
import os
import sys
import random
import time
random.seed(1234)
PATH = "/mnt/gdrive/large_random_file"
CHUNK_SIZE = 16*1024
CHUNKS_READ_COUNT = 1000
fh = os.open(PATH, os.O_RDONLY)
size = os.path.getsize(PATH)
readData = b''
start = time.time()
for _ in range(CHUNKS_READ_COUNT):
os.lseek(fh, random.randrange(size-CHUNK_SIZE), os.SEEK_SET)
readData += os.read(fh, CHUNK_SIZE)
end = time.time()
execution = end - start
print("Finished. Took {} seconds. Average {} reads per second".format(execution, CHUNKS_READ_COUNT / execution))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment