Sunday, February 10, 2013

Replacing Python with C Code

In an effort to speed things up, I've rewritten my maya python culling script into C.  Basically this means I'm doing the closest point on mesh and color lookup calculations myself instead of using pre-existing Maya nodes.

Both programs return the same results, just at different times.  The speed of the C program is related to the complexity of the mesh.  Below are some time trials I've completed to compare the efficiency of the methods.

S106- Top Mesh
Faces: 12992

10K Test Particles
Python: 61.1 seconds
C Code: 134 seconds

500K Test Particles
Python: 37 minutes
C Code: 107 minutes

M51- Stars
Faces: 2

500K Test Particles
Python: 35 minutes
C Code: 8 seconds

The C Code runs the code incredibly fast for simple meshes.  The speed could be improved for more complex meshes using various optimization techniques like reducing edge redundancy (currently checking non-boundary edges twice) and  spatial organization (octrees, kd trees, etc).  I believe we could probably get the C code to a state where it is similar in speed to the python script for S106, but I don't know if it could be faster.

I will most likely use a C implementation for the creation of the galaxy.  S106 is pretty much already created.

No comments:

Post a Comment