HDK
|
There are various approaches to creating new operators. This section describes how the same SOP can be written in 6 different ways.
Each of the 6 different approaches has advantages and disadvantages.
The following table lists approximate relative timings for the different implementations of the SOP:
Test | Time |
HOM/SOP_HOMWave.py | 11400ms |
HOM/SOP_HOMWave.C | 1070ms |
HOM/SOP_HOMWaveNumpy.py | 420ms |
HOM/SOP_HOMWaveInlinecpp.py | 275ms |
SOP/SOP_CPPWave.C | 275ms |
SOP/SOP_VEXWave.vfl | 245ms |
Notice that SOP/SOP_CPPWave.C, HOM/SOP_HOMWaveInlinecpp.py, and SOP/SOP_VEXWave.vfl run with close to the same performance. VEX can achieve similar performance as C++ primarily due to the fact that it is able to provide the following optimizations automatically:
HOM/SOP_HOMWaveNumpy.py is significantly faster than the HOM/SOP_HOMWave.py pure Python implementation because of the overhead of looping through all the points inside a Python loop.
HOM/SOP_HOMWave.py is slower than the C++ and VEX versions because it must continually allocate and deallocate HOM_Point objects as it iterates across points.
With regards to maintenance, the hands down winners are the VEX and Python implementations of the SOP. Since VEX and Python are scripting languages, the source is considerably shorter and doesn't require re-building between versions. It's marginally easier to create a VEX SOP since you can build an HDA directly from the command line (or graphically using VOPs).
Note the C++ code in the inlinecpp implementation is easier to maintain than the pure C++ implementation because:
Though VEX is fairly easy to use, VEX is designed around algorithms that apply across many elements simultaneously. This makes it very good and efficient at running over all points or primitives, but less effective if you have a very serial algorithm.
Writing a SOP in Python opens up the SOP to use any of the myriad modules which are available in Python. Sometimes, the flexibility in writing an operator in Python will outweigh the performance penalty.
By profiling your Python SOP with Python's cProfile module you can identify the slow portions and use the inlinecpp module to rewrite those portions in C++. As well, you can perform geometry operations not accessible from HOM by using inlinecpp to access the larger C++ HDK API.