Skip to content

Instantly share code, notes, and snippets.

@TriTechX
Last active October 2, 2024 11:27
Show Gist options
  • Select an option

  • Save TriTechX/dc8b6ef23bf2cc86fb6f67f1f71998e2 to your computer and use it in GitHub Desktop.

Select an option

Save TriTechX/dc8b6ef23bf2cc86fb6f67f1f71998e2 to your computer and use it in GitHub Desktop.
CPU Multicore Bench
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