Skip to content

Instantly share code, notes, and snippets.

@Axadiw
Created December 15, 2020 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Axadiw/c85d2b51c15d721a3f291eead8a4baa9 to your computer and use it in GitHub Desktop.
Save Axadiw/c85d2b51c15d721a3f291eead8a4baa9 to your computer and use it in GitHub Desktop.
#!/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