Advertisement
Guest User

IO-time

a guest
Sep 26th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. # -*- coding: utf8 -*-
  2.  
  3. from time import time
  4. from sys import argv
  5.  
  6. open_us = read_us = close_us = 0
  7.  
  8. for file in argv[1:]:
  9.     start = time()
  10.     with open(file) as f:
  11.         opened = time()
  12.         _ = f.read(4096)
  13.         read = time()
  14.     end = time()
  15.  
  16.     this_open_us = (opened - start) * 1000000
  17.     this_read_us = (read - opened) * 1000000
  18.     this_close_us = (read - opened) * 1000000
  19.     print "%s: %dµs + %dus + %dµs" % (file, this_open_us, this_read_us, this_close_us)
  20.  
  21.     open_us += this_open_us
  22.     read_us += this_read_us
  23.     close_us += this_close_us
  24.  
  25. count = len(argv) - 1
  26. open_us /= count
  27. close_us /= count
  28.  
  29. print "Avg Latency: %dµs + %dµs + %dµs = %dµs" % (open_us, this_read_us, close_us, open_us + read_us + close_us)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement