|
-
September 2nd, 2009, 12:55 PM
#8
Re: remove_if (not)
 Originally Posted by monarch_dodra
I'm wondering though, which is more efficient?
Code:
std::transform(ioString.begin(), ioString.end(), ioString.begin(), &tolower);
or
std::transform(ioString.begin(), ioString.end(), ioString.begin(), std::ptr_fun(&tolower));
Is there a difference in performance? I heard function objects are faster because the compiler can inline them, but in this case, the end result is that isalpha still has to be called?
I've read the same thing but I don't think that it justifies turning a library function into a functor in this case. I have a hard time believing that it would significantly improve your program. If you were writing your own predicate, as opposed to using a std library function, then I would always choose a functor over writing a global or static member function. Even then I'm not sure if the performance boost is really significant. I do it because I like the object orientedness of using functors, for lack of a better phrase. When passing a predicate by value to an algorithm, the functor concept seems more intuitive to me but I have never even bothered to measure the performance difference.
If you really wanted to know, you'd have to write a couple of sample programs and study the assembly code of each. You could also use some timestamps or a profiling tool to study the differences if you want. it might be useful to do that one time just to see for yourself what kind of a difference there is.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|