Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5554ee9

Browse filesBrowse files
Add ssl + hashlib benchmark
``` $ python3 --version && uname -a Python 3.10.12 Linux ip-172-31-89-138 6.2.0-1014-aws python#14~22.04.1-Ubuntu SMP Thu Oct 5 22:43:45 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux $ ./python bench/benchmarks.py; echo; python3 bench/benchmarks.py OPENSSL VERSION: AWS-LC 1.19.0 ALGO SIZE (B) TIME (s) ==== ======== ======== TLS 0 0.0007833797931671143 TLS 1024 0.0007857415676116944 TLS 1048576 0.002678983211517334 md5 8 1.9640922546386718e-06 md5 1024 3.949642181396484e-06 md5 1048576 0.0019850776195526124 sha1 8 1.847982406616211e-06 sha1 1024 3.45301628112793e-06 sha1 1048576 0.0014366722106933594 sha256 8 1.9931793212890624e-06 sha256 1024 5.559206008911133e-06 sha256 1048576 0.0035069866180419923 sha384 8 2.08735466003418e-06 sha384 1024 4.766225814819336e-06 sha384 1048576 0.0024656279087066652 sha512 8 2.061605453491211e-06 sha512 1024 4.767894744873047e-06 sha512 1048576 0.0024675443172454833 sha3_256 8 2.3877620697021486e-06 sha3_256 1024 6.785154342651367e-06 sha3_256 1048576 0.004528818607330322 sha3_384 8 2.38800048828125e-06 sha3_384 1024 7.86590576171875e-06 sha3_384 1048576 0.0058933842182159425 sha3_512 8 2.4230480194091797e-06 sha3_512 1024 1.0911941528320313e-05 sha3_512 1048576 0.008463276624679565 OPENSSL VERSION: OpenSSL 3.0.2 15 Mar 2022 ALGO SIZE (B) TIME (s) ==== ======== ======== TLS 0 0.0018935666084289552 TLS 1024 0.0019144091606140136 TLS 1048576 0.0029557681083679198 md5 8 1.8961429595947266e-06 md5 1024 3.826141357421875e-06 md5 1048576 0.0019944441318511964 sha1 8 1.855611801147461e-06 sha1 1024 3.2887458801269532e-06 sha1 1048576 0.001434556007385254 sha256 8 1.9848346710205076e-06 sha256 1024 5.077362060546875e-06 sha256 1048576 0.003089451551437378 sha384 8 2.099514007568359e-06 sha384 1024 4.216670989990234e-06 sha384 1048576 0.0020866355895996095 sha512 8 2.0647048950195313e-06 sha512 1024 4.217624664306641e-06 sha512 1048576 0.002087009906768799 sha3_256 8 2.408742904663086e-06 sha3_256 1024 5.91588020324707e-06 sha3_256 1048576 0.0037849726676940916 sha3_384 8 2.4039745330810547e-06 sha3_384 1024 6.922245025634765e-06 sha3_384 1048576 0.004906209945678711 sha3_512 8 2.3734569549560547e-06 sha3_512 1024 9.36126708984375e-06 sha3_512 1048576 0.007021739959716797 ```
1 parent 6a8c3e7 commit 5554ee9
Copy full SHA for 5554ee9

File tree

8 files changed

+124
-0
lines changed
Filter options

8 files changed

+124
-0
lines changed

‎bench/README.md

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# TODO

‎bench/benchmarks.py

Copy file name to clipboard
+81Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import csv
2+
import hashlib
3+
import multiprocessing
4+
import socket
5+
import ssl
6+
import time
7+
8+
9+
HOSTNAME = "127.0.0.1"
10+
SERVER_PORT = 4433
11+
12+
HASHES = [
13+
"md5",
14+
"sha1",
15+
"sha256",
16+
"sha384",
17+
"sha512",
18+
"sha3_256",
19+
"sha3_384",
20+
"sha3_512",
21+
]
22+
23+
24+
def main():
25+
server = multiprocessing.Process(target=start_server, daemon=True)
26+
server.start()
27+
time.sleep(0.5) # the server takes a little time to get going.
28+
print(f"OPENSSL VERSION: {ssl.OPENSSL_VERSION}")
29+
print(f"{'ALGO':^10} {'SIZE (B)':^10} {'TIME (s)':^20}")
30+
print(f"{'====':^10} {'========':^10} {'========':^20}")
31+
for size in 0, 1024, 1024**2:
32+
times = [run_client(size) for _ in range(1000)]
33+
print(f"{'TLS':<10} {size:<10} {sum(times)/len(times):<20}")
34+
for h in HASHES:
35+
for size in 8, 1024, 1024**2:
36+
times = [do_hash(h, size) for _ in range(1000)]
37+
print(f"{h:<10} {size:<10} {sum(times)/len(times):<20}")
38+
print()
39+
40+
41+
def do_hash(h: str, size: int) -> int:
42+
start = time.time()
43+
digest = hashlib.new(h)
44+
digest.update(b"X" * size)
45+
digest.digest()
46+
end = time.time()
47+
return end - start
48+
49+
50+
def run_client(size: int) -> int:
51+
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
52+
ctx.load_verify_locations("./bench/certs/CA.crt")
53+
ctx.check_hostname = False
54+
start = time.time()
55+
with ctx.wrap_socket(socket.socket(socket.AF_INET)) as conn:
56+
conn.connect((HOSTNAME, SERVER_PORT))
57+
if size > 0:
58+
conn.sendall(b"X" * size)
59+
end = time.time()
60+
return end - start
61+
62+
63+
def start_server():
64+
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
65+
ctx.load_cert_chain("./bench/certs/server.crt", "./bench/certs/server.key")
66+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) as sock:
67+
sock.bind((HOSTNAME, SERVER_PORT))
68+
sock.listen()
69+
with ctx.wrap_socket(sock, server_side=True) as ssock:
70+
while True:
71+
try:
72+
conn, addr = ssock.accept()
73+
except ssl.SSLEOFError:
74+
continue
75+
data = conn.recv(1024)
76+
while data:
77+
data = conn.recv(1024)
78+
79+
80+
if __name__ == "__main__":
81+
main()

‎bench/certs/CA.crt

Copy file name to clipboard
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIBljCCATugAwIBAgIUUlYFwDn054PXqbIMrrSUQ6HU8MowCgYIKoZIzj0EAwIw
3+
IDEeMBwGA1UEAwwVT1FTIHRlc3QgZWNkc2FwMjU2IENBMB4XDTIzMTIxMjE3MDkw
4+
MVoXDTI0MTIxMTE3MDkwMVowIDEeMBwGA1UEAwwVT1FTIHRlc3QgZWNkc2FwMjU2
5+
IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEJFgg8kGusiGvm+C5QeYhV0UZ
6+
qlMdkzHge7zAV3YRTA/g5exs5EujCVOY2tGIy0iKuEGP1M+toMbYmi7Vxb8HqKNT
7+
MFEwHQYDVR0OBBYEFDIAMFug9yRwdAANnGCwu6mzGSagMB8GA1UdIwQYMBaAFDIA
8+
MFug9yRwdAANnGCwu6mzGSagMA8GA1UdEwEB/wQFMAMBAf8wCgYIKoZIzj0EAwID
9+
SQAwRgIhAMIgAP5l7af9+gi1Yt1SR/fT/9PzAs/O0Tsapif3/RNgAiEAwe6MuVYu
10+
GdrEYpxX97yBSe2wioXrocda7CgDpUUIkaA=
11+
-----END CERTIFICATE-----

‎bench/certs/CA.key

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgFiXZaFCibucFMdxr
3+
WLkS9cLZor7Xxs3x4mi3RvyvbcShRANCAAQkWCDyQa6yIa+b4LlB5iFXRRmqUx2T
4+
MeB7vMBXdhFMD+Dl7GzkS6MJU5ja0YjLSIq4QY/Uz62gxtiaLtXFvweo
5+
-----END PRIVATE KEY-----

‎bench/certs/server.crt

Copy file name to clipboard
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIBOTCB4AIUZcuEo7Ou/R/+TLY3VtGOplZZqlgwCgYIKoZIzj0EAwIwIDEeMBwG
3+
A1UEAwwVT1FTIHRlc3QgZWNkc2FwMjU2IENBMB4XDTIzMTIxMjE3MDkwMVoXDTI0
4+
MTIxMTE3MDkwMVowHzEdMBsGA1UEAwwUb3FzdGVzdCBDQSBlY2RzYXAyNTYwWTAT
5+
BgcqhkjOPQIBBggqhkjOPQMBBwNCAASszcOdq5lgz1JdaYnCcdRVS0ELj2+37PpS
6+
ypNGmxuF5WDjMj/519xylbhOWQkx4/T3ZTNEDoVda5YFsJ4AJx/xMAoGCCqGSM49
7+
BAMCA0gAMEUCICMcvqeV5ygmyIv7Zbaq+kKPUE5cA48jlHNQwQTh17VxAiEA+pZ5
8+
FnKRW0xI90QHYL6Sy+B2gUpDA6bbRXs7EypeVA0=
9+
-----END CERTIFICATE-----

‎bench/certs/server.csr

Copy file name to clipboard
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-----BEGIN CERTIFICATE REQUEST-----
2+
MIHZMIGBAgEAMB8xHTAbBgNVBAMMFG9xc3Rlc3QgQ0EgZWNkc2FwMjU2MFkwEwYH
3+
KoZIzj0CAQYIKoZIzj0DAQcDQgAErM3DnauZYM9SXWmJwnHUVUtBC49vt+z6UsqT
4+
RpsbheVg4zI/+dfccpW4TlkJMeP092UzRA6FXWuWBbCeACcf8aAAMAoGCCqGSM49
5+
BAMCA0cAMEQCICCwHKUCevppkp8mIJ/i0+H1zR2SmmL6XDJ2DuDpIG6ZAiA3ihSC
6+
bTIXJe527hRxruB5937YwYlq1SVDqSjOyDh3Zw==
7+
-----END CERTIFICATE REQUEST-----

‎bench/certs/server.key

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgRqyThi/VpmwRI5Wm
3+
845G8JK2hQo5aR+F323suEOIkhKhRANCAASszcOdq5lgz1JdaYnCcdRVS0ELj2+3
4+
7PpSypNGmxuF5WDjMj/519xylbhOWQkx4/T3ZTNEDoVda5YFsJ4AJx/x
5+
-----END PRIVATE KEY-----

‎bench/run_benchmarks.sh

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
BUILD_DIR='build/bench/'
4+
5+
./python bench/benchmarks.py

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.