Skip to content

Instantly share code, notes, and snippets.

@walkingmask
Created December 19, 2017 07:10
Show Gist options
  • Save walkingmask/09ec6caddca39331ec482c075fc17a37 to your computer and use it in GitHub Desktop.
Save walkingmask/09ec6caddca39331ec482c075fc17a37 to your computer and use it in GitHub Desktop.
Testing multithreading
import multiprocessing
import time
def f(x):
for i in range(10**6):
x += i/x
return x
def main(n):
with multiprocessing.Pool(n) as p:
p.map(f, task)
if __name__ == '__main__':
print('cpu:', multiprocessing.cpu_count())
task = [i+1 for i in range(32)]
for i in range(1, 33):
s = time.clock()
main(i)
print(i, time.clock() - s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment