[patch, libstdc++] Optimize selection sampling by using generator to get two values at once

Jonathan Wakely jwakely@redhat.com
Fri Oct 21 15:55:00 GMT 2016


On 19/10/16 12:48 +0200, Eelis van der Weegen wrote:
>This is the same optimization as was recently applied to std::shuffle.
>
>It reduces the runtime of the following program by 20% on my machine:
>
>	int main()
>	{
>		std::vector<uint64_t> a(10000), b(1000);
>		std::mt19937 gen;
>
>		uint64_t c = 0;
>
>		for (int i = 0; i != 1000; ++i)
>		{
>			std::sample(a.begin(), a.end(), b.begin(), b.size(), gen);
>			c += uint64_t(b[32]);
>		}
>
>		std::cout << c;
>	}

Thanks, I've committd this slightly revised version to trunk (tweaking
some whitespace, removing some redundant std:: qualification, and
using foo_t<T> aliases instead of typename foo<T>::type).

Tested powerpc64le-linux. Committed to trunk.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 5360 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20161021/9b9005b7/attachment.bin>


More information about the Libstdc++ mailing list