import mmap import time FILE = '/tmp/spam' BLOCKS = 10000 LEN = 1000 # create file data = 'x' * LEN f = open(FILE, 'w+') for b in range(BLOCKS): f.write(data) f.flush() t = time.time() # mmap it, and write to memory for i in range(10): m = mmap.mmap(f.fileno(), 0) for b in range(BLOCKS): m.write(data) #m.flush() m.close() print(time.time() - t) f.close()