Computational speed Python vs. Cluster

Hi everyone,

I have created my first Python script! I wanted to compare the computational speed between coding with python and coding with the visual components of GH. I have coded the same problem using the same components and in this case, I obtained visual programming is faster. How is it possible? I thought it was just the opposite…Is there a way to optimise the python script done?

Moreover, I have duplicate four times the python script, giving four different computational times. Why is that happens? Shouldn’t it take the same time?

I appreciate your answers (18.7 KB) (13.1 KB)


Awesome what you did! Thank you so much, although I have some doubts.

Using this library (Rhino.Geometry) means the same of using this one (rhinoscryptsyntax)? What’s the difference?

What does it mean (from ghpythonlib.parallel import run)? Is the same as using import ghpythonlib.components?

Sorry for the answers and thanks for your patience!

Measuring and improving performance is not trivial. The whole system affects the computation, based on what your computer does next to your task. There are dozens, if not hundreds, of active background processes running on a Windows instance. So you will never get the same result.

Furthermore, scripting is not always faster, because you inject code into a system. So piping of data in and out of your script is always less-optimized than from a native component. Then you are not going to do the same procedures as the original component does, and the layer of access might also differ. Plus on the first execution the code needs to be compiled and loaded.

Rhinocommon is a wrapper around native Rhino functionality, and Rhinoscriptsyntax is a wrapper around Rhinocommon. Any layer on top comes with its own little performance costs.

You can only improve performance if you make something better than a native component, by improving the algorithm underneath. Often this is possible because a concrete use-case allows you to make some assumptions, or you simply combine multiple operations into one, reducing the amount of loops. On top of that, you can implement some language features like parallel computation or using more efficient data structures.

In the end, a performance gain below a magnitude is not worth the effort. The real benefit of scripting is getting a higher level of control, better readability and better handling of edge cases. If you want to write well performing code, you really need to know what you are doing.


Hi @TomTom I really appreciate your answer!

Lot of things still to learn!

Thank you again!

In addition to what Tom said, here’s a few specific things to consider that may speed up your GHPython components:

This might also help with wrapping your head around how Python is implemented in Rhino: