Oh no

Python performs 30 times slower than JS in my tests.
I've written a simple triangle filter
(sources python/JS/VBS below -- For testing I used a polymsh sphere, local subd refinement, Doo-Sabin, Level 4)
Python Output:
Quote:
# Execution time : 3388.01209812 ms
JS Output:
Quote:
# INFO : Execution time : 113 ms
VBS Output:
Quote:
' INFO : Execution Time = 93,75 ms
Maybe it's the way I use the for loop in python that's wrong .. no idea
C++ test still to go...
btw (from RCTools):
C# Output:
Quote:
// INFO : Execution time : 576 ms
Code:
import win32com.client
# Import the constants
from win32com.client import constants
from time import *
null = None
false = 0
true = 1
def XSILoadPlugin( in_reg ):
in_reg.Author = "Ray"
in_reg.Name = "PyBench Plug-in"
in_reg.Major = 1
in_reg.Minor = 0
in_reg.RegisterFilter("PyBench", constants.siFilterSubComponentPolygon)
#RegistrationInsertionPoint - do not remove this line
return true
def XSIUnloadPlugin( in_reg ):
strPluginName = in_reg.Name
Application.LogMessage(str(strPluginName) + str(" has been unloaded."),constants.siVerbose)
return true
# Match callback for the PyBench custom filter.
def PyBench_Match( in_ctxt ):
Application.LogMessage("PyBench_Match called", constants.siVerbose)
# Return value indicates if the input object matches the filter criterias.
return true
# Subset callback for the PyBench custom filter.
def PyBench_Subset( in_ctxt ):
Application.LogMessage("PyBench_Subset called", constants.siVerbose)
start = clock()
items = []
coll = XSIFactory.CreateObject("XSI.Collection")
in_objs = in_ctxt.GetAttribute("Input")
for obj in in_objs:
subc = obj.SubComponent
cc = subc.ComponentCollection
for poly in cc:
if poly.Points.Count < 4:
items.append(poly.Index)
oGeo = subc.Parent3DObject.ActivePrimitive.GetGeometry2( 0, constants.siConstructionModeSecondaryShape )
coll.Add( oGeo.CreateSubComponent("poly", items) )
in_ctxt.SetAttribute("Output", coll)
end = clock()
print("Execution time : " + str(1000*(end - start)) + " ms")
return true
# Init callback for the PyBench custom filter.
def PyBench_Init( in_ctxt ):
Application.LogMessage("PyBench_Init called", constants.siVerbose)
return true
Code:
function XSILoadPlugin( in_reg )
{
in_reg.Author = "Ray";
in_reg.Name = "JSBench Plug-in";
in_reg.Major = 1;
in_reg.Minor = 0;
in_reg.RegisterFilter("JSBench",siFilterSubComponentPolygon);
//RegistrationInsertionPoint - do not remove this line
return true;
}
function XSIUnloadPlugin( in_reg )
{
var strPluginName;
strPluginName = in_reg.Name;
Application.LogMessage(strPluginName + " has been unloaded.",siVerbose);
return true;
}
// Match callback for the JSBench custom filter.
function JSBench_Match( in_ctxt )
{
Application.LogMessage("JSBench_Match called",siVerbose);
// Return value indicates if the input object matches the filter criterias.
return true;
}
// Subset callback for the JSBench custom filter.
function JSBench_Subset( in_ctxt )
{
Application.LogMessage("JSBench_Subset called");
var start = new Date().getTime();
coll = new ActiveXObject("XSI.Collection");
in_objs = in_ctxt.GetAttribute("Input");
jsA = new Array();
e = new Enumerator(in_objs);
for(; !e.atEnd(); e.moveNext())
{
logmessage(e.item().type);
subc = e.item().SubComponent;
cc = subc.ComponentCollection;
e2 = new Enumerator(cc);
for(; !e2.atEnd(); e2.moveNext()) {
if(e2.item().Points.Count < 4)
jsA.push(e2.item().Index);
}
oGeo = subc.Parent3DObject.ActivePrimitive.GetGeometry(0, siConstructionMode.siConstructionModeSecondaryShape);
coll.Add( oGeo.CreateSubComponent("poly", jsA) );
}
in_ctxt.SetAttribute("Output", coll);
var end = new Date().getTime();
logmessage("Execution time : " + eval(end - start) + " ms");
// Return value indicates if a subset of the input objects matches the filter criterias.
return true;
}
// Init callback for the JSBench custom filter.
function JSBench_Init( in_ctxt )
{
Application.LogMessage("JSBench_Init called",siVerbose);
return true;
}
Code:
function XSILoadPlugin( in_reg )
in_reg.Author = "Ray"
in_reg.Name = "VBBench Plug-in"
in_reg.Major = 1
in_reg.Minor = 0
in_reg.RegisterFilter "VBBench",siFilterSubComponentPolygon
'RegistrationInsertionPoint - do not remove this line
XSILoadPlugin = true
end function
function XSIUnloadPlugin( in_reg )
dim strPluginName
strPluginName = in_reg.Name
Application.LogMessage strPluginName & " has been unloaded.",siVerbose
XSIUnloadPlugin = true
end function
' Match callback for the VBBench custom filter.
function VBBench_Match( in_ctxt )
Application.LogMessage "VBBench_Match called",siVerbose
' Return value indicates if the input object matches the filter criterias.
VBBench_Match = true
end function
' Subset callback for the VBBench custom filter.
function VBBench_Subset( in_ctxt )
Application.LogMessage "VBBench_Subset called",siVerbose
start = timer
set coll = CreateObject( "XSI.Collection" )
set in_objects = in_ctxt.GetAttribute( "Input" )
for each obj in in_objects
' get the edge object(s) from the subcomponent
set subc = obj.SubComponent
dim aIndices
nb_indices = 0
l_Array = subc.ElementArray
set l_Comps = subc.ComponentCollection
ReDim aIndices( ubound(l_Array) - lbound(l_Array) )
for each ply in l_Comps
if ply.Points.Count < 4 then
aIndices(nb_indices) = ply.Index
nb_indices = nb_indices + 1
end if
next
if nb_indices > 0 then
ReDim Preserve aIndices( nb_indices - 1 )
set oSubComponent = subc.Parent3DObject.activeprimitive.geometry.CreateSubComponent("poly", aIndices )
coll.Add oSubComponent
end if
next
in_ctxt.SetAttribute "Output", coll
endt = timer
LogMessage "Execution Time = " & 1000*(endt-start) & " ms"
VBBench_Subset = coll.Count > 04
end function
' Init callback for the VBBench custom filter.
function VBBench_Init( in_ctxt )
Application.LogMessage "VBBench_Init called",siVerbose
VBBench_Init = true
end function