-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmark_script.py
50 lines (40 loc) · 1.51 KB
/
benchmark_script.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
import os
import time
gosec_template = "gosec {}"
semgrep_template = "semgrep --config 'p/golang' -f {} --json"
# Path: benchmark_script.py
def benchmark_script_with_output(script_path):
"""
Runs the benchmark script and returns the result.
"""
# Path: benchmark_script.py
start_time = time.time()
output = os.popen(script_path).read()
end_time = time.time()
return end_time - start_time, output
def store(path, data):
with open(path, "w") as f:
f.write(data)
if __name__ == "__main__":
# Path: benchmark_script.py
# get all web frameworks paths using os.listdir
# and run the benchmark script for each of them
# and print the result
# Path: benchmark_script.py
frameworks_path = os.listdir(os.path.join(os.getcwd(), "frameworks"))
for framework in frameworks_path:
script_path = os.path.join("frameworks", framework)
print(f"Benchmarking {framework}")
print(script_path)
# Benchmarking framework on gosec
time_taken, output = benchmark_script_with_output(
gosec_template.format(script_path)
)
print(f"Gosec took {time_taken} seconds on {framework}")
store(f"gosec_results/{framework}.text", output)
# Benchmarking framework on semgrep
time_taken, output = benchmark_script_with_output(
semgrep_template.format(script_path)
)
print(f"Semgrep took {time_taken} seconds on {framework}")
store(f"semgrep_results/{framework}.text", output)