Jump to content

  • Log In with Google      Sign In   
  • Create Account

How efficient is glm when it returns the result


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 ill   Members   -  Reputation: 320

Like
0Likes
Like

Posted 08 November 2012 - 11:56 PM

I see many vector libraries take an argument as the destination to the result of something like dot product, cross product, etc... The destination is allocated and written to.

I see glm always returning a value instead which seems like it can be more expensive. I always think, is there some kind of compiler optimization or other stuff behind the scenes that makes the whole thing efficient after all and isn't something for me to worry about?

As an example of what I'm talking about:

[source lang="cpp"]//passing the result as a destinationvec3 result;dot(vecA, vecB, result);//returning the resultglm::vec3 result = glm::dot(vecA, vecB);[/source]

Sponsor:

#2 Lauris Kaplinski   Members   -  Reputation: 841

Like
1Likes
Like

Posted 09 November 2012 - 06:21 AM

  • You are right, this is not something you should worry about, unless you have profiled your program and identified it as a performance bottleneck. Plus chances are that if it will be the bottleneck then simply passing destination as function argument will not help you.
  • Yes, modern compilers should optimize out such assignments in release (optimized) mode.

Lauris Kaplinski

First technology demo of my game Shinya is out: http://lauris.kaplinski.com/shinya
Khayyam 3D - a freeware poser and scene builder application: http://khayyam.kaplinski.com/

#3 mhagain   Crossbones+   -  Reputation: 7969

Like
0Likes
Like

Posted 09 November 2012 - 07:02 AM

Yeah, generally this kind of thing falls into the realms of micro-optimization. You'd have to have a pretty extreme use-case for it to even register on any performance graph, so it's something that you really don't need to worry about.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#4 kloffy   Members   -  Reputation: 918

Like
1Likes
Like

Posted 09 November 2012 - 11:10 AM

I believe the relevant optimization technique here is Return value optimization.

Edited by kloffy, 09 November 2012 - 11:11 AM.


#5 ill   Members   -  Reputation: 320

Like
0Likes
Like

Posted 09 November 2012 - 03:57 PM

Ah very nice. Now I can stop worrying about this and just write code.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS