Jump to content
  • Advertisement
Sign in to follow this  
cypherx

Boost lambda performance?

This topic is 5007 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone here have experience using boost::lambda in a game or other high-performance application? Is it a hog? What's the difference in performance between
list<float> v(1000);
for_each(v.begin(), v.end(), _1 = 3.14f);

and
list<float> v(1000); 
for (list<float>::iterator iter=v.begin(); iter != iter.end(); iter++)
{
(*iter) = 3.14f; 
}

Thanks, Alex

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
i can't answer your questin directly, as i've never used the lambda library. but i found this on the boost site:
http://www.boost.org/doc/html/lambda/s07.html#id546544
these are performance comparisons.

do people actually use the lambda stuff in real projects? i kind of like the idea behind it.

Share this post


Link to post
Share on other sites
I use it occasionally

It's nice to not have to make a seperate function to print a container
cout << _1 << constant(endl)

But I'd use it more if it didn't crash my VS.NET (anyone else experience this?)

Share this post


Link to post
Share on other sites
Quote:
Original post by cypherx
What's the difference in performance between

list<float> v(1000);
for_each(v.begin(), v.end(), _1 = 3.14f);


and

list<float> v(1000);
for (list<float>::iterator iter=v.begin(); iter != iter.end(); iter++)
{
(*iter) = 3.14f;
}



First of all why anyone would want to do that when you can do:


std::list<float> v(1000, 3.14f);


or use fill/_n algorithms but i know its just an example.

Back to the question, regardless of using boost lambdas already the for_each code is mostly likely going to better in performance for 2 reasons, 1. using post-increment opereators on iterators can be very inefficent, 2. your invoking the member function *end* each time around the loop when you only need to call it once.

On a good modern, mostly standard compliant and optimizing compiler most of the lamdba stuff will be inlined away and it will be like using for_each with a named functor.

Quote:
Original post by cypherx
Does anyone here have experience using boost::lambda in a game or other high-performance application? Is it a hog?


Quote:
Original post by Anonymous Poster
do people actually use the lambda stuff in real projects? i kind of like the idea behind it.


Yes i have been using it, and using it happily, i have no intention of writing one off functors/functions for simple code. I have a profiler and the overhead is pretty much negliable to nothing, how-ever i don't go nuts with it & STL and use it randomally, i think i've learn't to use the standard library & some of boost libraries very effectively.

This is the thing if you lack knowledge of using these components your going to suffer and suffer badly with inefficent code, you'll start making assumptions then end up blaming the tools your using when its really you not using it wright/well because you don't understand or not enough about it.

I suggest if it makes your code more simple, cleaner, nicer to read go with it, don't worry about it to much (but don't be ignorant) and just profile your code later.

[Edited by - snk_kid on March 1, 2005 8:22:26 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!