Created
August 23, 2011 01:43
-
-
Save kosaki/1164110 to your computer and use it in GitHub Desktop.
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
=== threading === | |
#!/usr/bin/python | |
import sys | |
import threading | |
THR_NUM=4 | |
class thr(threading.Thread) : | |
def run(self) : | |
val = 0 | |
while val < 100000000 : | |
val = val + 1 | |
num_of_thr = 0 | |
t = [] | |
while num_of_thr < THR_NUM : | |
t.append(thr()) | |
num_of_thr = num_of_thr + 1 | |
for x in t : | |
x.start() | |
for x in t : | |
x.join() | |
=== | |
$ time ./cpubench.py | |
real 0m58.897s | |
user 0m57.655s | |
sys 1m31.172s // !?!? | |
multiprocessing | |
== | |
#!/usr/bin/python | |
import sys | |
import multiprocessing | |
THR_NUM=4 | |
class thr(multiprocessing.Process) : | |
def run(self) : | |
val = 0 | |
while val < 100000000 : | |
val = val + 1 | |
num_of_thr = 0 | |
t = [] | |
while num_of_thr < THR_NUM : | |
t.append(thr()) | |
num_of_thr = num_of_thr + 1 | |
for x in t : | |
x.start() | |
for x in t : | |
x.join() | |
== | |
$ time ./cpubench2.py | |
real 0m5.519s | |
user 0m21.829s | |
sys 0m0.013s | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment