-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfiling.py
More file actions
35 lines (27 loc) · 928 Bytes
/
Profiling.py
File metadata and controls
35 lines (27 loc) · 928 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
import cProfile
import pstats
import sys
import random
import matplotlib.pyplot as plt
from SimulatorDiscrete import Simulator
if __name__ == "__main__":
profiler = cProfile.Profile()
profiler.enable()
sim = Simulator()
sim.load_config("profilingConfig.json")
sim.Parameters_Test()
sim.run()
profiler.disable()
plt.hist(sim.latency_times, bins=20, color='skyblue', edgecolor='black')
plt.title('Latency Distribution')
plt.xlabel('Latency Time (s)')
plt.ylabel('Frequency')
plt.show()
# Generate a random integer and append to the filename
random_number = random.randint(1000, 9999)
filename = f'profiling_output_{random_number}.txt'
with open(filename, 'w') as f:
stats = pstats.Stats(profiler, stream=f)
stats.sort_stats('cumulative')
stats.print_stats()
print(f"Profiling results are written to '{filename}'.")