-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperformance_comparison.py
78 lines (64 loc) · 2.1 KB
/
performance_comparison.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
import time
import os
from kerberos_auth import main
from oauth2_auth import fetch_protected_resource, get_access_token
import matplotlib.pyplot as plt
from jinja2 import Template
# Create results directory if it doesn't exist
os.makedirs('results', exist_ok=True)
# Measure Kerberos performance
start_time = time.time()
main()
kerberos_time = time.time() - start_time
# Measure OAuth performance
start_time = time.time()
token = get_access_token()
user_info = fetch_protected_resource(token)
oauth_time = time.time() - start_time
# Format user info: If it's a dictionary, join the key-value pairs into a string
if isinstance(user_info, dict):
formatted_user_info = '\n'.join([f"{key}: {value}" for key, value in user_info.items()])
else:
# Handle case where user_info is not a dictionary (fallback)
formatted_user_info = user_info
# Log results
with open("results/results.txt", "w") as f:
f.write(f"Kerberos Time: {kerberos_time:.2f}s\n")
f.write(f"OAuth Time: {oauth_time:.2f}s\n")
f.write(f"OAuth User Info:\n{formatted_user_info}\n")
# Data for chart
protocols = ['Kerberos', 'OAuth 2.0']
times = [kerberos_time, oauth_time]
# Create bar chart
plt.bar(protocols, times, color=['blue', 'green'])
plt.title("Authentication Performance Comparison")
plt.xlabel("Protocols")
plt.ylabel("Time (seconds)")
plt.savefig("results/performance_chart.png")
plt.close()
# Report Template
report_template = """
# Cryptographic and Authentication Protocol Comparison
## Results
- **Kerberos Authentication Time**: {{ kerberos_time }} seconds
- **OAuth 2.0 Authentication Time**: {{ oauth_time }} seconds
## User Info from OAuth
```
{{ formatted_user_info }}
```
## Performance Chart

"""
# Data for the report
data = {
"kerberos_time": kerberos_time,
"oauth_time": oauth_time,
"formatted_user_info": formatted_user_info,
}
# Render the report
template = Template(report_template)
report_content = template.render(data)
# Save the report
with open("results/report.md", "w") as f:
f.write(report_content)
print("Performance comparison completed and archived.")