Because I needed to use an array in array for my function (I believe) I use the python zip function to make an array of arrays.
I find that the function that was written in python was amazingly slower than the regular grasshopper function. Am I doing something wrong or is the zip thing slowing everything down?
import ghpythonlib.components as ghcomp
import ghpythonlib.parallel
z = zip(x, y)
def rule_surf(i):
return ghcomp.RuledSurface(i[0], i[1])
a = ghpythonlib.parallel.run(rule_surf, z, True)
The very first time a script is run there is a large overhead with respect to initializing the python runtime and “compiling” the script.If this is what you are looking at with respect to performance times then you are getting mislead by the numbers.
Here’s something to try. Add another input to your python component (call it z since that’s what the default will create and we won’t really use it.) Wire a toggle up to the z input and don’t change any of your code. Now click the toggle on and off and look at the performance times change. python zip example.gh (8.7 KB)
You don’t need to restart Rhino. I meant that the very first time your grasshopper definition is evaluated with a python script in it, there is some overhead which will produce slower performance results than you expect.
Open the grasshopper definition that you sent and just start double clicking on the toggle a bunch of times. You’ll see that the performance dramatically improves for the python component after a couple toggles.
As a side note, I wouldn’t personally multithread this component since it already runs extremely fast in serial.
Multithreaded C# will be marginally faster, but it will be a lot more work. I am using the term marginally because you typically are multithreading calls into other functions in Rhino which take a long time. C# and python are typically a thin layer of glue code that call into larger library functions written in lower level rhino C++ code.