So I’d love to only use python and not Tscript, but there seems to be a huge performance gap, I’m wondering where it’s coming from ?
I did a simple test where I’m adding two chops using an expression chop.
Tscript is $V+ic(1,0,$I)
Python is me.inputVal+op(‘constant2’)[0][me.curSample]
For 3000 samples, Tscript expression chop cook time is 2 ms, Python expression chop is 13 ms.
For reference, math chop is 0.02 ms…
And to be complete I did a c++ chop add, which gives 0.03ms (looks like there’s some little overhead?)
See attached test file.
This is ultimately to drive geometry instances transforms.
So as expected c++ is the way to go for performance, but it’s a bit disappointing python is so slow, which makes it barely usable even for prototyping except for light geometry.
I guess it would be the same for custom attributes in a point SOP.
Any way to make it faster? Else I’m going back honing my tscript expressions skills for now!
When I use a script CHOP however, it gets much faster, especially when I use numpy to add the arrays, making it faster than the tscript expression CHOP even:
Without numpy:
def cook(scriptOP):
a = scriptOP.inputs[0]
b = scriptOP.inputs[1]
scriptOP.copy(a)
t1 = scriptOP[0]
t2 = b[0]
l = scriptOP.numSamples
for i in range(l):
t1[i] += t2[i]
return
Thanks for the quick reply.
Well that’s interesting and good to know!
Indeed even the script chop without numpy is faster than the expression chop with tscript.
On my system :
Script chop without numpy : 1.4 ms
Script chop with numpy : 1.1 ms
Also I did one more expression chop with
me.inputVal+(me.inputs[1])[0][me.curSample]
and this is 7 ms, so already a lot faster than with the op() function.