View difference between Paste ID: 9jkmb2vJ and AXaHGeZi
SHOW: | | - or go back to the newest paste.
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
read_us /= count
28
close_us /= count
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)
29+
30
print "Avg Latency: %dµs + %dµs + %dµs = %dµs" % (open_us, read_us, close_us, open_us + read_us + close_us)