Rhino PythonScript commands slower than equivalent VBScript?

python
rhino5

#1

Hi everyone,

First of all, I am using Rhino5(64-bit) on Windows 7.

To give some background on the problem I am having, I have rewritten a VBScript using Python for Rhino (personal preferences, I would like to stick to python for the ‘simple’ scripts I am doing), which allows the user to select surfaces, which are then exported in a .csv file where we can find (SurfaceName, SurfaceID, SurfaceLayerName, SurfaceArea, SurfaceAreaCentroid[X], SurfaceAreaCentroid[Y], SurfaceAreaCentroid[Z], SurfaceNormalVector[X], SurfaceNormalVector[Y], SurfaceNormalVector[Z]), each line corresponding to one of the surfaces exported.

Now, my issue is that when I run both codes, which are very similar and rely on the exact same rhino commands, on a rhino model of a stadium (which is split in 1500 small surfaces), the VBScript takes 1min30 while the PythonScript takes 5min to produce the same result.

I did many versions of the python code where I have been optimising string concatenation and writing operations, but in the end it was not very relevant because when I study the time taken by the commands in the for loop, it appears that the bottleneck is when I extract the Area and the AreaCentroid of the surface (each taking around 2min30, so both together are nearly 100% of execution time). But both the VBScrip and the Python script use the methods SurfaceArea() and SurfaceAreaCentroid().

	for strSurfaceID in arrSurfaceIDs:

		(...some other code here...)

		arrSurfaceArea = rs.SurfaceArea(strSurfaceID)
		arrSurfaceCentroid = rs.SurfaceAreaCentroid(strSurfaceID)

		(...some other code here...)

So, in conclusion, I’m wondering why those exact same commands are executed faster by VB than Python.

Many thanks for your attention, I look forward to discuss this.

Regards,

Damien


#2

I think you cannot expect too much discussion here as things are improved in WIP:


#3

Thanks for the answer, so unless I use GrassHopper, VBScript is going to be faster than Python?


#4

I think Python is generally faster in WIP…


#5

Okay, thanks. But WIP stands for Work In Progress, right? Does that mean Rhino 6, Rhino 7 ?


#6

Serengeti == WIP == 6 == True


#7

Got it, thanks a lot :slight_smile:


(Steve Baer) #8

Hi Damien,
RhinoScript and Python are both providing very a very thin layer above the exact same C++ code that is computing SurfaceArea and SurfaceAreaCentriod. I’m wondering if there is some subtle difference in the logic when you rewrote the script in a different language.