I did some tests to check how much speed i can gain with the .NET threading librarys in Ironpython.
The results were far from good:
long list with some Vector3d Multiplication
threading sequence in list: 12121212
same list access: read + write
vectorTask: 1 threads 5.580 sec
vectorTask: 2 threads 3.890 sec
vectorTask: 4 threads 3.042 sec
same list access: read only
vectorTask: 1 threads 4.420 sec
vectorTask: 2 threads 2.569 sec
vectorTask: 4 threads 1.879 sec
2 lists: one read, one write
vectorTask: 1 threads 5.650 sec
vectorTask: 2 threads 4.270 sec
vectorTask: 4 threads 3.238 sec
i see… but maybe i do something else wrong -
here is the test script i wrote (just one list, read + write)
import Rhino
import System
import time
import rhinoscriptsyntax as rs
from Rhino import RhinoApp
from scriptcontext import doc
from System.Threading import Thread, ThreadStart, ParameterizedThreadStart
def RunCommand():
RhinoApp.ClearCommandHistoryWindow()
print("****************************")
iter = 5000000 # number of operations
vec = [Rhino.Geometry.Vector3d(1,1,1)] * iter # populate the list
thread = [] # threads
threadnum = 4 # number of threads
def vectorTask(id):
# the xrange jumps in steps of threadnum,
# i thought that it could be faster by chunking the tasks
# instead of jumping through the list (read somewhere about branch prediction)
# but didnt help either
for i in xrange(id,iter,threadnum):
vec[i] = Rhino.Geometry.Vector3d.Multiply(1.234, vec[i])
start = time.time()
for i in xrange(0,threadnum):
thread.append(Thread(ParameterizedThreadStart(vectorTask)))
for i in xrange(0,threadnum):
thread[i].Start(i)
for i in xrange(0,threadnum):
thread[i].Join()
print("vectorTask: "+str(threadnum)+" threads "+str(time.time()-start)[:5]+ " sec"); doc.Views.Redraw(); RhinoApp.Wait()
if __name__ == "__main__":
RunCommand()