-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_experiment.py
129 lines (97 loc) · 3.81 KB
/
run_experiment.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
128
129
#!/usr/bin/env python
from mbased.experiments.experiment import run_experiment
import argparse
import matplotlib.pyplot as plt
import numpy as np
def generate_plot(res) -> None:
orig_op_counts: list[int] = []
obf_op_counts: list[int] = []
simplified_op_counts: list[int] = []
orig_var_counts: list[int] = []
obf_var_counts: list[int] = []
simplified_var_counts: list[int] = []
labels: list[str] = []
for experiment in res:
orig_op_counts.append(experiment[2])
obf_op_counts.append(experiment[5])
simplified_op_counts.append(experiment[8])
orig_var_counts.append(experiment[3])
obf_var_counts.append(experiment[6])
simplified_var_counts.append(experiment[9])
labels.append(f"N={experiment[0]}")
op_formatted_experiments: dict[str, list[int]] = {
# "Original": orig_op_counts,
"Obfuscated": obf_op_counts,
"Simplified": simplified_op_counts,
}
var_formatted_experiments: dict[str, list[int]] = {
# "Original": orig_var_counts,
"Obfuscated": obf_var_counts,
"Simplified": simplified_var_counts,
}
x: np.ndarray = np.arange(len(labels))
width: float = 0.25
multiplier: int = 0
fig, axes = plt.subplots(2, 2, layout="constrained")
ax1: plt.Axes = axes[0, 0]
ax2: plt.Axes = axes[1, 0]
ax3: plt.Axes = axes[0, 1]
ax4: plt.Axes = axes[1, 1]
for attribute, measurement in op_formatted_experiments.items():
offset = width * multiplier
rects = ax1.bar(x + offset, measurement, width, label=attribute)
ax1.bar_label(rects, padding=3)
multiplier += 1
ax1.set_title("Number Operations", y=1.02)
ax1.set_xticks(x + width, labels)
ax1.legend(loc="upper left", ncols=3)
ax1.tick_params(axis="both", which="major", labelsize=4, rotation=70)
multiplier: int = 0
for attribute, measurement in var_formatted_experiments.items():
offset = width * multiplier
rects = ax2.bar(x + offset, measurement, width, label=attribute)
ax2.bar_label(rects, padding=3)
multiplier += 1
ax2.set_title("Number Variables", y=1.02)
ax2.set_xticks(x + width, labels)
ax2.legend(loc="upper left", ncols=3)
ax2.tick_params(axis="both", which="major", labelsize=4, rotation=70)
experiment_range: np.array = np.arange(len(res))
for attribute, measurement in op_formatted_experiments.items():
ax3.plot(experiment_range, measurement, label=attribute)
ax3.legend(loc="upper left", ncols=3)
ax3.set_title("Number Operations", y=1.02)
ax3.set_xticks(x + width, labels)
ax3.legend(loc="upper left", ncols=3)
ax3.tick_params(axis="both", which="major", labelsize=4, rotation=70)
for attribute, measurement in var_formatted_experiments.items():
ax4.plot(experiment_range, measurement, label=attribute)
ax4.legend(loc="upper left", ncols=3)
ax4.set_title("Number Variables", y=1.02)
ax4.set_xticks(x + width, labels)
ax4.legend(loc="upper left", ncols=3)
ax4.tick_params(axis="both", which="major", labelsize=4, rotation=70)
plt.show()
if __name__ == "__main__":
parser: argparse.ArgumentParser = argparse.ArgumentParser(
description="Runs MBA simplification experiment"
)
parser.add_argument(
"--plot", action="store_true", help="Display plots of the data."
)
parser.add_argument(
"--npasses",
type=int,
nargs=1,
help="Sets the number of passes to run.",
)
args: argparse.Namespace = parser.parse_args()
passes: list[str] = ["sympy_pass"]
if args.npasses:
res = run_experiment(passes, args.npasses[0])
else:
res = run_experiment(passes)
print("========================================")
print(res)
if args.plot:
generate_plot(res)