-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
29 lines (25 loc) · 862 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from multiprocessing.pool import ThreadPool
import multiprocessing
import time
def seq(count):
print "runing seq"
start_time = time.time()
result = []
for i in range(count):
result.append(cube(i))
print "seq --- time:{0:.4f}".format(time.time() - start_time)
#print "seq --- time:{0:.4f}, result:{1}".format(time.time() - start_time, result)
def par(count):
print "runing par"
start_time = time.time()
result = ThreadPool(processes=4).map(cube,range(count))
#result = multiprocessing.Pool(processes=4).map(cube,range(count))
print "par --- time:{0:.4f}".format(time.time() - start_time)
#print "par --- time:{0:.4f}, result:{1}".format(time.time() - start_time, result)
def cube(x):
#time.sleep(.01)
return x*x*x
if __name__ == "__main__":
count = 40000000
seq(count)
par(count)