-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.py
More file actions
35 lines (28 loc) · 922 Bytes
/
benchmark.py
File metadata and controls
35 lines (28 loc) · 922 Bytes
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
import time
import hashlib
import multiprocessing
def hash_benchmark(n):
for i in range(n):
hashlib.sha256(str(i).encode()).hexdigest()
def main():
num_hashes = 20000000 # CPU load, increase or decrease according to need
'''
Running Benchmark on CPU (16 Cores)...
Single Core Time: 13.07 seconds
Multi Core Time: 2.84 seconds
'''
print(f"Running Benchmark on CPU ({multiprocessing.cpu_count()} Cores)...")
# Single Core Test
start = time.time()
hash_benchmark(num_hashes)
end = time.time()
print(f"Single Core Time: {end - start:.2f} seconds")
# Multi Core Test
start = time.time()
with multiprocessing.Pool() as pool:
# distribute load on different process
pool.map(hash_benchmark, [num_hashes//8]*8)
end = time.time()
print(f"Multi Core Time: {end - start:.2f} seconds")
if __name__ == '__main__':
main()