-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_run.py
More file actions
158 lines (130 loc) · 5.38 KB
/
Copy pathbenchmark_run.py
File metadata and controls
158 lines (130 loc) · 5.38 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import os, sys
from time import perf_counter as time
from random import shuffle
write_size_MB = [1024, 10] # size MB to save
write_block_size_kB = [1024*100, 1024*10]
read_size_MB = 1000
read_block_size_kB = 1024*100
def read_test(directory, block_size, blocks_count):
print("%d block size, %d blocks" % ( block_size, blocks_count))
f = os.open(directory, os.O_RDONLY | os.O_BINARY)
offsets = list(range(0, blocks_count*block_size, block_size))
shuffle(offsets)
took = []
for i, offset in enumerate(offsets):
print("%d iteration, %d offset" % (i, offset))
bytes_read = 0
start = time()
test = ""
position_cursor = os.lseek(f, offset, os.SEEK_SET)
while bytes_read < block_size:
buff = os.read(f, block_size-bytes_read)
print("%d postition cursor, %d offset" % (position_cursor, offset))
print("%d block bytes remainning" % (block_size-bytes_read))
print("%d buff size" % (len(buff)))
# print(buff)
bytes_read = bytes_read + len(buff)
if (len(buff)>0):
test = buff[0]
if len( buff) ==0:
print("EOF reached")
break # if EOF reached
print("%d bytes_read " % (bytes_read))
t = time() - start
took.append(t)
result=block_size*blocks_count / 1024/1024/sum(took)
print("Reading speed result: %.2f MB/s" % result)
def read_test_normal(directory, block_size, blocks_count):
print("%d block size, %d blocks" % ( block_size, blocks_count))
offsets = list(range(0, blocks_count * block_size, block_size))
shuffle(offsets)
with open(directory, "rb") as f:
took = []
for i, offset in enumerate(offsets):
print("%d iteration, %d offset" % (i, offset))
bytes_read = 0
start = time()
test = ""
position_cursor = f.seek(offset, os.SEEK_SET) # os.lseek(f, offset, os.SEEK_SET)
while bytes_read < block_size:
buff = f.read(block_size - bytes_read)
print("%d postition cursor, %d offset" % (position_cursor, offset))
print("%d block bytes remainning" % (block_size - bytes_read))
print("%d buff size" % (len(buff)))
# print(buff)
bytes_read = bytes_read + len(buff)
if (len(buff) > 0):
test = buff[0]
if len(buff) == 0:
print("EOF reached")
break # if EOF reached
print("%d bytes_read " % (bytes_read))
t = time() - start
took.append(t)
result=block_size*blocks_count / 1024/1024/sum(took)
print("Reading speed result: %.2f MB/s" % result)
# def write_test(directory, block_size, blocks_count):
# print("%s block size, %s blocks" % ( block_size, blocks_count))
# f = os.open(directory, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o777)
# took = []
# for i in range(blocks_count):
# buff = os.urandom(block_size)
# start = time()
# os.write(f, buff)
# os.fsync(f)
# t = time() - start
# took.append(t)
# print("Block nr %d done in %.2f s" % (i + 1, t))
# os.close(f)
# result = block_size*blocks_count / 1024 / 1024 / sum(took)
# print("Writing speed result: %.2f MB/s" % result)
# return result
def write_test(directory, block_size, blocks_count):
print("%s block size, %s blocks" % (block_size, blocks_count))
took = []
with open(directory, "wb") as f:
for i in range(blocks_count):
buff = os.urandom(block_size)
start = time()
f.write(buff)
f.flush()
t = time() - start
took.append(t)
print("Block nr %d done in %.2f s" % (i + 1, t))
result = block_size*blocks_count / 1024 / 1024 / sum(took)
print("Writing speed result: %.2f MB/s" % result)
return result
def read_test2(directory, block_size, blocks_count):
print("%d block size, %d blocks" % ( block_size, blocks_count))
with open(directory, 'r') as f:
buff = f.read()
print(buff)
# offsets = list(range(0, blocks_count*block_size, block_size))
# shuffle(offsets)
# took = []
# for i, offset in enumerate(offsets):
# print("%d iteration" % (i))
# bytes_read = 0
# start = time()
# while bytes_read < block_size:
# # os.lseek(f, offset+bytes_read, os.SEEK_SET)
# # print("%d block bytes remainning" % (block_size-bytes_read))
# # print("%d buff size" % (len(buff)))
# bytes_read = bytes_read + len(buff)
# if len( buff) ==0:
# print("EOF reached")
# break # if EOF reached
# # print("%d bytes_read " % (bytes_read))
# t = time() - start
# took.append(t)
# os.close(f)
# result=block_size*blocks_count / 1024/1024/sum(took)
# print("Reading speed result: %.2f MB/s" % result)
def main():
directory = 'E:\\testy'
# directory = 'C:\\Users\\wojci\\testy'
# for i in range(len(write_size_MB)):
i = 0
write_test(directory, write_block_size_kB[i]*1024, int(write_size_MB[i]*1024/write_block_size_kB[i]))
# read_test(directory, read_block_size_kB*1024,int(read_size_MB * 1024 / read_block_size_kB))
# main()