#!/usr/bin/python import sys import time import os # 500k of data to write data = "*" * 524288 count = 4096 # record open time and open the file start = time.time() f = os.open(sys.argv[1], os.O_WRONLY | os.O_CREAT | os.O_TRUNC) # open done open_end = time.time() # write 2G and track write end while count: os.write(f, data) count -= 1 write_end = time.time() # sync the file and track sync end os.fsync(f) sync_end = time.time() # close the file and track close end os.close(f) close_end = time.time() # Now print each chunk of time print """Time in seconds open %f write %f fsync %f close %f """ % (open_end - start, write_end - open_end, sync_end - write_end, close_end - sync_end) # Total time spend on creating the file print "Total time: %f seconds" % (close_end - start)