c++ - Which one is more memory-consuming? Matrix or trigonometry transformations -
i have written 2 different ways transform euler angles normalized unit direction vector. i'm not sure 1 faster. 1 uses trigonometry operations or 1 transforms forward vector through matrix?
d3dxvector3 eulertodir(d3dxvector3 eulerrotation) { return d3dxvector3(sin(eulerrotation.x)*cos(eulerrotation.y), -sin(eulerrotation.y), cos(eulerrotation.x)*cos(eulerrotation.y)); }//convert euler angles unit direction vector. d3dxvector3 eulertodirm(d3dxvector3 eulerrotation)//same thing using matrix transformation. more accurate. { d3dxmatrix rotmat; d3dxmatrixrotationyawpitchroll(&rotmat, eulerrotation.x, eulerrotation.y, eulerrotation.z); d3dxvector3 resultvec(0, 0, 1);//facing towards z. d3dxvec3transformnormal(&resultvec, &resultvec, &rotmat); return resultvec; }
thanks.
well, care about? memory usage stated in top level question? or speed, specified in description?
if it's speed, real way tell measure on target architecture/environment. trying guess waste of time.
the easiest way test performance of self-containted code snippets setup unit test this:
// setup first time starttime = getcurrenttimeinmicros() (int = 0; < num_iterations; ++i) { // code performance tested } time endtime = getcurrenttimeinmicros()
then can endtime - starttime , see code took longer run.
if need test memory usage, print out sizeof() classes/structs if simple, else allocate them while instrumenting code valgrind/massif.
Comments
Post a Comment