Last active
October 2, 2024 11:27
-
-
Save TriTechX/dc8b6ef23bf2cc86fb6f67f1f71998e2 to your computer and use it in GitHub Desktop.
CPU Multicore Bench
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import multiprocessing as mp | |
| import time | |
| import math | |
| N=5000000 | |
| def root(x): | |
| return math.sqrt(x) | |
| time_total=[] | |
| for x in range(1, 20): | |
| with mp.Pool() as pool: | |
| start_time = time.perf_counter() | |
| result = pool.map(root, range(10,N)) | |
| finish_time = time.perf_counter() | |
| time_total.append(finish_time-start_time) | |
| print("Round {}: done.".format(x)) | |
| total=0 | |
| amount=0 | |
| for x in time_total: | |
| total+=x | |
| amount+=1 | |
| avgTime = total/amount | |
| print("Done in {} average seconds/operation".format(avgTime)) | |
| score = round(((10/avgTime))*1000) | |
| print("Score: {}".format(score)) | |
| f=open("cbsopenfile","w") | |
| f.write(str(score)) | |
| f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment