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

Eelis van der Weegen eelis@eelis.net
Wed Oct 19 10:48:00 GMT 2016


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;
	}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: double-step-selection-sample.patch
Type: text/x-patch
Size: 4053 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20161019/23082dc6/attachment.bin>


More information about the Libstdc++ mailing list