-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-graph.py
127 lines (112 loc) · 3.93 KB
/
gen-graph.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import contextlib
import json
import sys
from pathlib import Path
import matplotlib.pyplot as plt
if __name__ == "__main__":
if len(sys.argv) != 3:
raise ValueError(
"Wrong use of this file. Please use `python gen-graph.py -n <name>`"
)
name = None
for index, arg in enumerate(sys.argv):
if arg == "-n":
name = sys.argv[index + 1]
if name is None:
raise ValueError(
"Wrong use of this file. Please use `python gen-makefile.py -n <name>`"
)
data_path = f"maked/without_nfs/server/json_storage/{name}"
with contextlib.suppress(FileExistsError):
path = Path(data_path).glob("**/*.json")
files = [x for x in path if x.is_file()]
without_nfs = []
for file in files:
with open(file) as f:
data = json.load(f)
without_nfs.append((str(file).split("/")[-1].split(".")[0], data))
data_path = f"maked/with_nfs/server/json_storage/{name}"
with contextlib.suppress(FileExistsError):
path = Path(data_path).glob("**/*.json")
files = [x for x in path if x.is_file()]
with_nfs = []
for file in files:
with open(file) as f:
data = json.load(f)
with_nfs.append((str(file).split("/")[-1].split(".")[0], data))
with_nfs = sorted(with_nfs, key=lambda x: int(x[0]))
without_nfs = sorted(without_nfs, key=lambda x: int(x[0]))
# Extract x-values and ensure they are sorted
x_values = sorted(
set(
[int(elem[0]) for elem in with_nfs] + [int(elem[0]) for elem in without_nfs]
)
)
# Apply a nicer style
plt.style.use("seaborn-darkgrid")
# First figure: Execution times
fig, ax = plt.subplots(figsize=(10, 6))
make_duration = without_nfs[0][1]["makeDuration"]
ax.plot(
[int(elem[0]) for elem in without_nfs],
[make_duration / 1_000_000 for _ in without_nfs],
color="tab:red",
label="Make",
marker="o",
)
ax.plot(
[int(elem[0]) for elem in with_nfs],
[elem[1]["makedDuration"] / 1_000_000 for elem in with_nfs],
color="tab:blue",
label="Maked (with NFS)",
marker="o",
)
ax.plot(
[int(elem[0]) for elem in without_nfs],
[elem[1]["makedDuration"] / 1_000_000 for elem in without_nfs],
color="tab:orange",
label="Maked (without NFS)",
marker="o",
)
ax.set_xlabel("Number of nodes", fontsize=12)
ax.set_ylabel("Execution time (s)", fontsize=12)
ax.set_title(f"Makefile Execution Times: {name}", fontsize=14)
ax.set_xticks(x_values)
ax.legend(fontsize=12)
ax.grid(True)
fig.tight_layout()
plt.savefig(f"maked/without_nfs/server/json_storage/{name}/speed-compare.png")
plt.close(fig)
# Second figure: Relative speed increase
fig, ax = plt.subplots(figsize=(10, 6))
# Note: Ensure division by zero does not occur. If makedDuration = 0, handle gracefully.
def relative_speed(data):
return [
(make_duration / d["makedDuration"] * 100)
if d["makedDuration"] != 0
else None
for d in data
]
ax.plot(
[int(elem[0]) for elem in with_nfs],
relative_speed([elem[1] for elem in with_nfs]),
color="tab:blue",
label="Maked (with NFS)",
marker="o",
)
ax.plot(
[int(elem[0]) for elem in without_nfs],
relative_speed([elem[1] for elem in without_nfs]),
color="tab:orange",
label="Maked (without NFS)",
marker="o",
)
ax.set_xlabel("Number of nodes", fontsize=12)
ax.set_ylabel("Relative speed increase (%)", fontsize=12)
ax.set_title(f"Makefile Execution Relative Speed Increase: {name}", fontsize=14)
ax.set_xticks(x_values)
ax.legend(fontsize=12)
ax.grid(True)
fig.tight_layout()
plt.savefig(f"maked/without_nfs/server/json_storage/{name}/speed-relative.png")
plt.close(fig)