-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbenchmark-buf.py
More file actions
executable file
·60 lines (43 loc) · 1.45 KB
/
benchmark-buf.py
File metadata and controls
executable file
·60 lines (43 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python
#
# Author: Ian Gable <igable@uvic.ca>
#
# Script that checks write time for different read buffer sizes
#
import sys
import os
import time
from optparse import OptionParser
parser = OptionParser(usage="%prog -i INFILE -o OUTFILE",version = "%prog 0.1")
parser.add_option("-i", "--infile", dest="infile",
help="The file to read from", metavar="INFILE")
parser.add_option("-o","--outfile",dest="outfile",
help="The file to write to", metavar="OUTFILE")
parser.add_option("-b", action="store_true", dest="isbinary", default=False)
(options, args) = parser.parse_args()
isbinary = options.isbinary
if not (options.outfile and options.infile):
parser.print_help()
parser.error("")
#buffersizes doubling starting with 1 KB
buffers = [2**13, 2**14, 2**15, 2**16, 2**17, 2**18, 2**19, 2**20, 2**21, 2**22, 2**23, 2**24, 2**25]
src = options.infile
outfile = options.outfile
#src = "/tmp/datain"
#outfile = "/tmp/dataout"
for bufsize in buffers:
fin=open(src,'r')
if isbinary:
fout=open(outfile,'wb')
else:
fout=open(outfile,'w')
start = time.time()
while True:
buf=fin.read(bufsize)
if len(buf)==0:
break
fout.write(buf)
fout.close()
fin.close()
elapsed = time.time() - start
print "The elepsed time for buffer "+ str(bufsize/8192) + " KB: " + str(elapsed) + " s"