Skip to content

Instantly share code, notes, and snippets.

@nikalras
Created March 5, 2015 02:46
Show Gist options
  • Select an option

  • Save nikalras/5a6496e73604e032abf6 to your computer and use it in GitHub Desktop.

Select an option

Save nikalras/5a6496e73604e032abf6 to your computer and use it in GitHub Desktop.
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