-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
32 lines (25 loc) · 1.14 KB
/
main.c
File metadata and controls
32 lines (25 loc) · 1.14 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
#include "common.h"
int main() {
int (*algorithms[])(Memory *, char, int, int) = {FIFO, LRU, LFU, MFU, RandomPick};
char *algorithmNames[] = {"FIFO", "LRU", "LFU", "MFU", "RandomPick"};
for (int i = 0; i < 5; i++) {
JobQueue jobQueue;
generateWorkload(&jobQueue); // Regenerate workload for each algorithm
double hitRatioSum = 0, missRatioSum = 0;
int swappedInSum = 0;
for (int run = 0; run < 5; run++) {
Memory memory;
initializeMemory(&memory);
runSimulation(&jobQueue, &memory, algorithms[i], algorithmNames[i], &hitRatioSum, &missRatioSum, &swappedInSum);
}
double avgHitRatio = hitRatioSum / 5;
double avgMissRatio = missRatioSum / 5;
double avgSwappedIn = (double)swappedInSum / 5;
printf("\n=== Average Results for %s Algorithm ===\n", algorithmNames[i]);
printf("Average Hit Ratio: %.2f\n", avgHitRatio);
printf("Average Miss Ratio: %.2f\n", avgMissRatio);
printf("Average Processes Swapped-In: %.2f\n", avgSwappedIn);
printf("---------------------------------\n");
}
return 0;
}