This repository has been archived by the owner on Oct 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
56 lines (49 loc) · 1.91 KB
/
main.py
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
from fifo import fifo
from lru import lru
from prepare import prepare
from load import load
# exit codes:
# 0 - correct execution
# 1 - unexpected outcome in lru
# 3 - input data file not found
def run(select="both", frames=3, pages=20, verbose="no"):
if select == "fifo":
chain = load()
average = 0
for i in chain:
w = fifo(i, frames, pages, verbose=verbose)
print("\nPage faults for second chance FIFO:", w, end='')
average += w
average /= len(chain)
print("\nAverage page faults for second chance FIFO", average)
with open("output_fifo.csv", "a") as f:
f.write("\nAverage page faults for FIFO " + str(average))
elif select == "lru":
chain = load()
average = 0
for i in chain:
w = lru(i, frames, pages, verbose)
print("\nPage faults for LRU:", w, end='')
average += w
average /= len(chain)
print("\nAverage page faults for LRU", average)
with open("output_lru.csv", "a") as f:
f.write("\nAverage page faults for LRU " + str(average))
else:
chain = load()
average_fifo = average_lru = 0
for i in chain:
average_fifo += fifo(i, frames, pages, verbose=verbose)
average_lru += lru(i, frames, pages, verbose=verbose)
average_fifo /= len(chain)
average_lru /= len(chain)
print("\nAverage page faults for second chance FIFO", average_fifo)
with open("output_fifo.csv", "a") as f:
f.write("\nAverage page faults for FIFO " + str(average_fifo))
print("\nAverage page faults for LRU", average_lru)
with open("output_lru.csv", "a") as f:
f.write("\nAverage page faults for LRU " + str(average_lru))
if __name__ == "__main__":
S = 20
# prepare(length=100, pages=S, chains=100)
run("both", frames=9, pages=S, verbose="yes")