boost::function performance issues with C++11
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? int func2(std::vector<int> i){ total += i.size(); return i.size(); } 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(); In case you need to know my enviorment, my OS is Arch, compiler is gcc 4.9.0, and optimizations are default. 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
On Thu, Jul 3, 2014 at 4:10 PM, 饭桶
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
Hi Michael,
Thanks for your suggestion. I understand that using a reference or a pointer will achieve better performance, and I really appreciate you pointed out that for me.
But I intend to do this to highlight my point, that the performance are quite different with or without -std=c++11. And I'm really curious about that.
Consider a situiation, that I'm using boost::function. However, the performance could be seriously affected by using a compiling flag (-std=c++11). That will be very weired to me, unless someone can tell me what happens there.
BTW, when I say default, I mean release mode.
Thanks
Xuepeng
At 2014-07-04 07:55:39, "Michael Powell"
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
I guess that with -std=c++11 the compiler may not do all the possible
optimizations, since c++11 is "new".
How about go wild and use -O3 as compilation flag?
This will give more freedom to the compiler optimization, and maybe more
velocity.
2014-07-03 21:23 GMT-03:00 饭桶
Hi Michael,
Thanks for your suggestion. I understand that using a reference or a pointer will achieve better performance, and I really appreciate you pointed out that for me. But I intend to do this to highlight my point, that *the performance are quite different with or without -std=c++11*. And I'm really curious about that.
Consider a situiation, that I'm using boost::function. However, the performance could be seriously affected by using a compiling flag (-std=c++11). That will be very weired to me, unless someone can tell me what happens there.
BTW, when I say default, I mean release mode. Thanks Xuepeng
At 2014-07-04 07:55:39, "Michael Powell"
wrote: 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
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
Maybe trying another compiler would help you obtain your "proof".
How about intel compiler?
It also has the "-std=c++11" flag, so, if it is a compiler issue it will be
clear.
2014-07-03 22:22 GMT-03:00 饭桶
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"
wrote: I guess that with -std=c++11 the compiler may not do all the possible optimizations, since c++11 is "new". How about go wild and use -O3 as compilation flag? This will give more freedom to the compiler optimization, and maybe more velocity.
2014-07-03 21:23 GMT-03:00 饭桶
: Hi Michael,
Thanks for your suggestion. I understand that using a reference or a pointer will achieve better performance, and I really appreciate you pointed out that for me. But I intend to do this to highlight my point, that *the performance are quite different with or without -std=c++11*. And I'm really curious about that.
Consider a situiation, that I'm using boost::function. However, the performance could be seriously affected by using a compiling flag (-std=c++11). That will be very weired to me, unless someone can tell me what happens there.
BTW, when I say default, I mean release mode. Thanks Xuepeng
At 2014-07-04 07:55:39, "Michael Powell"
wrote: 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
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Thu, Jul 3, 2014 at 7:23 PM, 饭桶
Hi Michael,
Thanks for your suggestion. I understand that using a reference or a pointer will achieve better performance, and I really appreciate you pointed out that for me. But I intend to do this to highlight my point, that the performance are quite different with or without -std=c++11. And I'm really curious about that.
Consider a situiation, that I'm using boost::function. However, the performance could be seriously affected by using a compiling flag (-std=c++11). That will be very weired to me, unless someone can tell me what happens there.
Well, you're testing potentially two things: STL performance, or std::bind performance. Couldn't tell you which is the bottleneck, but neither in my mind are trivial depending how many elements are in your vector.
BTW, when I say default, I mean release mode. Thanks Xuepeng
At 2014-07-04 07:55:39, "Michael Powell"
wrote: 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
Right, there are 1000 integers in the vector. If something, say STL, is bottleneck for boost::bind with C++ 11, it should also be a bottleneck without C++11. And they should have the same performance. However, the fact shows that C++11 mode has some additional overhead. I wanna figure that out.
Thanks
Athrun
At 2014-07-04 11:10:28, "Michael Powell"
On Thu, Jul 3, 2014 at 7:23 PM, 饭桶
wrote: Hi Michael,
Thanks for your suggestion. I understand that using a reference or a pointer will achieve better performance, and I really appreciate you pointed out that for me. But I intend to do this to highlight my point, that the performance are quite different with or without -std=c++11. And I'm really curious about that.
Consider a situiation, that I'm using boost::function. However, the performance could be seriously affected by using a compiling flag (-std=c++11). That will be very weired to me, unless someone can tell me what happens there.
Well, you're testing potentially two things: STL performance, or std::bind performance. Couldn't tell you which is the bottleneck, but neither in my mind are trivial depending how many elements are in your vector.
BTW, when I say default, I mean release mode. Thanks Xuepeng
At 2014-07-04 07:55:39, "Michael Powell"
wrote: 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
Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 4 Jul 2014 at 5:10, wrote:
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? [snip] In case you need to know my enviorment, my OS is Arch, compiler is gcc 4.9.0, and optimizations are default. 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!
I'd check C++ 11 mode on GCC 4.6. It could be as simple as an outdated GCC version switch. Niall -- ned Productions Limited Consulting http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/
On 03.07.2014 23:10, 饭桶 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?
int func2(std::vector<int> i){ total += i.size(); return i.size(); }
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();
In case you need to know my enviorment, my OS is Arch, compiler is gcc 4.9.0, and optimizations are default. 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!
Hi! I'd run the example code through Callgrind (valgrind --tool=callgrind) and then compare the reports in KCachegrind. This should at least give you an idea of the source of the problem. I may do that myself during the weekend in case you would not able to do that on your own. WBR, Adam Romanek
Cool, that maybe helpful. I will try it and see if I can identify any thing interestring here.
Thanks
Athrun
At 2014-07-04 08:10:46, "Adam Romanek"
On 03.07.2014 23:10, 饭桶 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?
int func2(std::vector<int> i){ total += i.size(); return i.size(); }
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();
In case you need to know my enviorment, my OS is Arch, compiler is gcc 4.9.0, and optimizations are default. 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!
Hi!
I'd run the example code through Callgrind (valgrind --tool=callgrind) and then compare the reports in KCachegrind. This should at least give you an idea of the source of the problem.
I may do that myself during the weekend in case you would not able to do that on your own.
WBR, Adam Romanek
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 05.07.2014 01:23, 饭桶 wrote:
Cool, that maybe helpful. I will try it and see if I can identify any thing interestring here.
Thanks Athrun
At 2014-07-04 08:10:46, "Adam Romanek"
wrote: On 03.07.2014 23:10, 饭桶 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?
int func2(std::vector<int> i){ total += i.size(); return i.size(); }
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();
In case you need to know my enviorment, my OS is Arch, compiler is gcc 4.9.0, and optimizations are default. 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!
Hi!
I'd run the example code through Callgrind (valgrind --tool=callgrind) and then compare the reports in KCachegrind. This should at least give you an idea of the source of the problem.
I may do that myself during the weekend in case you would not able to do that on your own.
As promised I performed a simple test during the weekend and wasn't able
to reproduce the issue. See the code below:
---
#include <vector>
#include
On Tuesday, July 08, 2014 06:11 PM, Adam Romanek wrote:
As promised I performed a simple test during the weekend and wasn't able to reproduce the issue. See the code below:
--- #include <vector> #include
#include void call(boost::function
f) { f(); } long long total = 0;
int func2(std::vector<int> i){ total += i.size(); return i.size(); }
int main() { std::vector<int> v(100); 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(); } ---
The performance does not change when compiling with -std=c++11 or without it. I compile the code like this:
$ g++ -I/home/A.Romanek/tmp/boost/boost_1_55_0 main.cpp -std=c++11 -O2 && time ./a.out
real 0m1.669s
My setup is Ubuntu 14.04, gcc 4.8.2 and my CPU is Intel Core2Duo P8700 @ 2.53GHz.
Could you please provide a complete example so that I could reproduce the issue on my desk?
Make of this what you will, I used your example: g++-4.8.2 -std=c++03 -std=c++11 real 0m0.753s 0m0.798s user 0m0.752s 0m0.797s sys 0m0.001s 0m0.002s g++-4.9 -std=c++03 -std=c++11 real 0m0.786s 0m1.419s user 0m0.785s 0m1.418s sys 0m0.001s 0m0.002s clang++-3.4 (libstdc++ from g++-4.9) -std=c++03 -std=c++11 real 0m0.799s 0m1.407s user 0m0.798s 0m1.406s sys 0m0.001s 0m0.002s clang++-3.4 (libc++ trunk) -std=c++03 -std=c++11 real 0m1.382s 0m1.389s user 0m1.381s 0m1.387s sys 0m0.002s 0m0.002s clang++-3.5 (libstdc++ from g++-4.9) -std=c++03 -std=c++11 real 0m0.812s 0m1.112s user 0m0.811s 0m1.111s sys 0m0.002s 0m0.002s clang++-3.5 (libc++ trunk) -std=c++03 -std=c++11 real 0m0.782s 0m0.770s user 0m0.781s 0m0.769s sys 0m0.002s 0m0.002s Ben
participants (6)
-
Adam Romanek
-
Angelo Mondaini
-
Ben Pope
-
Michael Powell
-
Niall Douglas
-
饭桶