-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIO_bound.py
More file actions
52 lines (42 loc) · 1.56 KB
/
IO_bound.py
File metadata and controls
52 lines (42 loc) · 1.56 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
import os
import time
# Function to simulate reading files
def read_file(file_path):
with open(file_path, 'r') as file:
data = file.read()
return data
# Function to create a file with sample content
def create_file(file_path, content, size_mb):
with open(file_path, 'w') as file:
while file.tell() < size_mb * 1024 * 1024:
file.write(content)
if __name__ == "__main__":
# Define file names and their sizes in MB
files = {
'file1.txt': 1, # 1 MB
'file2.txt': 1, # 1 MB
'file3.txt': 1,
'file4.txt': 1,
'file5.txt': 1,
'file6.txt': 1,
'file7.txt': 1,
'file8.txt': 1,
'file9.txt': 1,
'file10.txt': 1 # 1 MB
}
# Define sample content to fill the files
content = "This is a sample line of text.\n"
start_time = time.time()
# Create files with the specified sizes
for file_name, size_mb in files.items():
create_file(file_name, content, size_mb)
print(f"Created {file_name} with size {size_mb} MB")
print("Sample files created successfully.\n")
# Example list of files to read
files = ['file1.txt', 'file2.txt', 'file3.txt', 'file4.txt', 'file5.txt', 'file6.txt', 'file7.txt', 'file8.txt', 'file9.txt', 'file10.txt']
for i in files:
os.remove(i)
print("all text files deleted")
end_time = time.time()
execution_time = end_time - start_time # Total execution time
print(f"\n\nExecution Time: {execution_time:.4f} seconds")