Created
March 5, 2015 02:46
-
-
Save nikalras/5a6496e73604e032abf6 to your computer and use it in GitHub Desktop.
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 time | |
| nb_repeat = 50 | |
| def a_complex_operation(*args): | |
| a = [] | |
| for x in range(999999): | |
| a.append(x) | |
| return None | |
| t1 = time.time() | |
| for _ in range(nb_repeat): | |
| a_complex_operation() | |
| print time.time()-t1 | |
| from multiprocessing import Pool | |
| nb_repeat = 50 | |
| def a_complex_operation(*args): | |
| a = [] | |
| for x in range(999999): | |
| a.append(x) | |
| return None | |
| pool = Pool(processes=nb_repeat) | |
| results = pool.map(a_complex_operation, [None for _ in range(nb_repeat)]) | |
| from threading import Thread | |
| import time | |
| nb_repeat = 50 | |
| def a_complex_operation(*args): | |
| a = [] | |
| for x in range(999999): | |
| a.append(x) | |
| return None | |
| t1 = time.time() | |
| threads = [] | |
| for _ in range(nb_repeat): | |
| threads.append(Thread(target=a_complex_operation)) | |
| [x.start() for x in threads] | |
| [x.join() for x in threads] | |
| print time.time()-t1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment