I am working on a program that performs matrix and vector operation in Java. Multiple function calls and the creation of objects that occur in my current implementation make it sluggish and difficult to understand.
For example, I want to update the position of a mechanical point by integrating speed:
void update(Vector3 position, Vector3 speed, float dt){ Vector3 displacement = new Vector3(speed); displacement.assignMul(dt); position.assignAdd(displacement); }
Here the API is not natural, and in addition, I need to highlight the assembly of the new Vector3 link. Obviously, I measured a big performance improvement in the case of real-world applications when building computations this way:
void update(Vector3 position, Vector3 speed, float dt){ position.x += speed.x * dt; position.y += speed.y * dt; position.z += speed.z * dt; }
Is there any tool that could generate this code from a specific domain upon request? Cog syntax will be nice. (Cog is a code creation tool from Ned Batchelder)
void update(Vector3 position, Vector3 speed, float dt){
source share