Thanks, that helps. But still there are only about 7 times slower.
Specifically, the performance difference only happens when passing a vector as parameter. I tried passing reference and shared pointer, they are kind of similar to boost::function.
So here is my guess according to your suggestion. Maybe std::function uses copying code that can be easier optimized. But that's just my guess, still need proof.
-Athrun
At 2014-07-04 08:50:00, "Angelo Mondaini"
On Thu, Jul 3, 2014 at 4:10 PM, 饭桶
wrote: Hi,
Does anyone know why -std=c++11 causes so much difference on boost::function?
I was planed to understand if there any performance issues with big size of parameters. So I wrote a function that takes a vector as parameter, like func2 shows. I know it's better to use a pointer or reference as function parameter. I just want to evaluate the performance, so let's keep the vector as parameter.
However, I found that it's quite slow when compiled with -std=c++11. In detail, it takes 173874 milliseconds with C++11, while it takes 3676 seconds without C++11.
About 50 times slower!! How can that be?
In my opinion, I thought boost::function should had the same performance with std::function. So I decided to try std::function in C++11 directly, Finally, it takes about 29233 milliseconds. That's till 8 times slows!
Can anyone tell me what happend here?
I don't know the inner workings of either boost::function or std::function. It's not boost's fault per se, but there are a couple of things you could do differently.
int func2(std::vector<int> i){ total += i.size(); return i.size(); }
Pass a reference or even a pointer instead of the whole vector. You are copying the vector every time.
const int T = 1000000; s = boost::chrono::system_clock::now(); for (int i = 0; i < T; ++i) call(boost::bind(&func2, v)); e = boost::chrono::system_clock::now();
You are also binding func2 every time; not sure if that's getting optimized or not.
You likely want to bind with a placeholder instead of the vector itself, then call the binding itself. i.e.
auto binding = boost::bind(&func2, _1); binding(v);
I do that frequently enough; and with more event-driven systems, boost::signals, etc, it is unavoidable. You want the placeholder instead, once-bound/later-called.
In case you need to know my enviorment, my OS is Arch, compiler is gcc 4.9.0, and optimizations are default.
Default can mean a lot of things. Debug or release mode? Beyond those two broad categories, do verify your settings and build for release mode.
HTH
The execution time (ms) of three versions I tried: boost::function with C++11 : 173874 boost::function without C++11 : 3676 std::function in C++11 : 29233
Any thoughts are appreciated! Thanks, Athrun
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users