This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Exploit move semantics in std::accumulate.


On 8 Jan 2011, at 17:27, Eelis van der Weegen wrote:

> The attached simple patch reduces the runtime of the following program
> from 1.4 seconds to 0.005 seconds on my machine:
> 
>  #include <iostream>
>  #include <string>
>  #include <numeric>
>  #include <vector>
> 
>  int main()
>  {
>    std::vector<std::string> v;
>    for(int i = 0; i != 20000; ++i)
>      v.push_back(std::string(50, 'a'+(i%10)));
> 
>    std::cout << std::accumulate(v.begin(), v.end(),
>      std::string()).size() << '\n';
>  }

Your patch is a really nice idea. I'm not 100% sure it is allowed by the C++0x standard (although, I can't imagine any valid code which would possibly break it).

Chris


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]