-
Notifications
You must be signed in to change notification settings - Fork 0
/
Algorithm_Analyze.py
64 lines (54 loc) · 3 KB
/
Algorithm_Analyze.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
57
58
59
60
61
62
63
64
from Process_Analyze import *
def get_terminate_time(terminated_queue):
finish_time = terminated_queue.array[0].termination_time
for i in range(1, terminated_queue.size):
if terminated_queue.array[i].termination_time > finish_time:
finish_time = terminated_queue.array[i].termination_time
return finish_time
def get_CPU_execution_time(job_queue):
CPU_execution_time = 0
for i in range(job_queue.size):
CPU_execution_time += job_queue.array[i].CPU_burst_time_1 + job_queue.array[i].CPU_burst_time_2
return CPU_execution_time
def get_CPU_utilization_percent(job_queue, terminated_queue):
CPU_execution_time = get_CPU_execution_time(job_queue)
finish_time = get_terminate_time(terminated_queue)
return (CPU_execution_time / finish_time) * 100
def get_CPU_idle_time(job_queue, terminated_queue):
finish_time = get_terminate_time(terminated_queue)
CPU_execution_time = get_CPU_execution_time(job_queue)
return finish_time - CPU_execution_time
def get_throughput(terminated_queue):
finish_time = get_terminate_time(terminated_queue)
return finish_time / float(terminated_queue.size)
def get_average_turnaround_time(terminated_queue):
average_turnaround_time = 0
for i in range(terminated_queue.size):
average_turnaround_time += get_process_turnaround_time(terminated_queue.array[i])
return average_turnaround_time / terminated_queue.size
def get_average_waiting_time(terminated_queue):
average_waiting_time = 0
for i in range(terminated_queue.size):
average_waiting_time += get_process_waiting_time(terminated_queue.array[i])
return average_waiting_time / terminated_queue.size
def get_average_response_time(terminated_queue):
average_response_time = 0
for i in range(terminated_queue.size):
average_response_time += terminated_queue.array[i].response_time
return average_response_time / terminated_queue.size
def analyze_algorithm_on_the_queue(job_queue, terminated_queue, output_file):
CPU_execution_time = get_CPU_execution_time(job_queue)
CPU_idle_time = get_CPU_idle_time(job_queue, terminated_queue)
CPU_utilization = get_CPU_utilization_percent(job_queue, terminated_queue)
throughput = get_throughput(terminated_queue)
average_turnaround_time = get_average_turnaround_time(terminated_queue)
average_waiting_time = get_average_waiting_time(terminated_queue)
average_response_time = get_average_response_time(terminated_queue)
output_file.write("*****\nAlgorithm Analysis:\n")
output_file.write(f"*\nCPU execution time: {CPU_execution_time}\n")
output_file.write(f"*\nCPU idle time: {CPU_idle_time}\n")
output_file.write(f"*\nCPU utilization: {CPU_utilization:.2f}%\n")
output_file.write(f"*\nThroughput: {throughput:.2f}\n")
output_file.write(f"*\nAverage turnaround time: {average_turnaround_time:.2f}\n")
output_file.write(f"*\nAverage waiting time: {average_waiting_time:.2f}\n")
output_file.write(f"*\nAverage response time: {average_response_time:.2f}\n")