Created
December 19, 2017 07:10
-
-
Save walkingmask/09ec6caddca39331ec482c075fc17a37 to your computer and use it in GitHub Desktop.
Testing multithreading
This file contains 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 | |
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