-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfifo_code.py
More file actions
38 lines (31 loc) · 990 Bytes
/
Copy pathfifo_code.py
File metadata and controls
38 lines (31 loc) · 990 Bytes
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
# VIRTUAL MEMORY MAPPING
def fifo_c(data, frames):
string = list(map(int, data.split()))
len_str = len(string)
hit = 0
j = 0
memory = []
for i in range(frames):
memory.append('')
for i in range(len_str):
if j >= frames:
j = 0
if string[i] in memory:
hit += 1
else:
memory[j] = string[i]
j += 1
# print(memory)
miss = len(string) - hit
hit_ratio = hit/len(string)
return hit, miss, memory, hit_ratio
"""
# DRIVER
string = list(map(int, input("Enter all string val::").split()))
frames = int(input("No. of Frames: "))
hit, memory = fifo(string, frames)
print('\n{:<20}{}{}'.format('Cache Memory', ': ', memory))
print('{:<20}{}{}'.format('Total no. of HITS', ': ', hit))
print('{:<20}{}{}'.format('Total no. of Miss', ': ', len(string) - hit))
print('{:<20}{}{:.2f}'.format('HIT ratio', ': ', hit/len(string)))
"""