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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
import threading
import sys
import numpy as np
# Disable the @profile decorator if none has been declared.
try:
# Python 2
import __builtin__ as builtins
except ImportError:
# Python 3
import builtins
try:
builtins.profile
except AttributeError:
# No line profiler, provide a pass-through version
def profile(func): return func
builtins.profile = profile
class MyThread(threading.Thread):
@profile
def run(self):
z = 0
z = np.random.uniform(0,100,size=2 * 5000);
# print("thread1")
class MyThread2(threading.Thread):
@profile
def run(self):
z = 0
for i in range(5000 // 2):
z += 1
# print("thread2")
use_threads = True
# use_threads = False
if use_threads:
for i in range(10000):
t1 = MyThread()
t2 = MyThread2()
t1.start()
t2.start()
t1.join()
t2.join()
else:
t1 = MyThread()
t1.run()
t2 = MyThread2()
t2.run()
|