This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch, libstdc++] std::shuffle: Generate two swap positions at a time if possible
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Eelis <eelis at eelis dot net>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 3 May 2016 13:38:55 +0100
- Subject: Re: [patch, libstdc++] std::shuffle: Generate two swap positions at a time if possible
- Authentication-results: sourceware.org; auth=none
- References: <ng536o$4iu$1 at ger dot gmane dot org> <ng53cl$4iu$2 at ger dot gmane dot org>
ENOPATCH
On 1 May 2016 at 15:21, Eelis <eelis@eelis.net> wrote:
> Sorry, forgot to include the libstdc++ list.
>
> On 2016-05-01 16:18, Eelis wrote:
>>
>> Hi,
>>
>> The attached patch optimizes std::shuffle for the very common case
>> where the generator range is large enough that a single invocation
>> can produce two swap positions.
>>
>> This reduces the runtime of the following testcase by 37% on my machine:
>>
>> int main()
>> {
>> std::mt19937 gen;
>>
>> std::vector<int> v;
>> v.reserve(10000);
>> for (int i = 0; i != 10000; ++i)
>> {
>> v.push_back(i);
>> std::shuffle(v.begin(), v.end(), gen);
>> }
>>
>> std::cout << v.front() << '\n';
>> }
>>
>> Thoughts?
>>
>> Thanks,
>>
>> Eelis
>>
>
>