Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #91227

Re: "Inside STL: The map, set, multimap, and multiset" by Raymond Chen

From Bonita Montero <Bonita.Montero@gmail.com>
Newsgroups comp.lang.c++
Subject Re: "Inside STL: The map, set, multimap, and multiset" by Raymond Chen
Date 2023-08-09 14:52 +0200
Organization A noiseless patient Spider
Message-ID <ub026o$3uqs6$1@dont-email.me> (permalink)
References (1 earlier) <aaa09f64-8320-4b9f-bd86-91d800de81e1n@googlegroups.com> <uavbi9$3q20f$1@dont-email.me> <28833c3b-c58f-48f5-8ce4-6bbdce6f58d3n@googlegroups.com> <uavumo$3ttih$1@dont-email.me> <f1354b8a-5e4e-455d-b355-9f3a090d7600n@googlegroups.com>

Show all headers | View raw


Am 09.08.2023 um 14:10 schrieb Öö Tiib:
> On Wednesday, 9 August 2023 at 14:53:14 UTC+3, Bonita Montero wrote:
>> Am 09.08.2023 um 12:08 schrieb Öö Tiib:
>>> Great example, intersting how std::bitset<500000> and
>>> std::vector<bool>(500000) perform compared to that "my_set".
>> With this code bitset and vector<bool> have the same performance
>> under Windows (MSVC) and Linux (g++ / clang++).
>>
>> uniform_int_distribution<size_t> iBit( 0, BITS - 1 );
> 
> Unused variable "iBit", must be your test tests some other test case
> as "distr" of Paavo was used in his tests.

I made it even shorter:

#include <iostream>
#include <bitset>
#include <vector>
#include <random>
#include <chrono>
#include <atomic>

using namespace std;
using namespace chrono;

atomic<size_t> aSum;

int main()
{
	constexpr size_t BITS = 0x10000;
	bitset<BITS> bs;
	vector<bool> vb( BITS );
	mt19937_64 mt;
	auto fill = []( auto &container )
	{
		bool bit = false;
		for( size_t i = 0; i != BITS; ++i )
			container[i] = bit,
			bit = !bit;
	};
	fill( bs );
	fill( vb );
	constexpr size_t ROUNDS = 10'000;
	auto bench = []( char const *what, auto const &container, auto next )
	{
		auto start = high_resolution_clock::now();
		size_t sum = 0;
		for( size_t r = ROUNDS; r--; )
			for( size_t g = 0, i = 0; g != BITS; ++g, i = next( i ) )
				sum += container[i];
		double ns = duration_cast<nanoseconds>( high_resolution_clock::now() - 
start ).count() / ((double)BITS * ROUNDS);
		::aSum = sum;
		cout << what << ns << endl;
	};
	auto linear = []( size_t i ) { return i + 1; };
	bench( "linear bitset: ", bs, linear );
	bench( "linear vector: ", vb, linear );
	auto gapped = []( size_t i ) { return i + 7 < BITS ? i + 7 : 0; };
	bench( "gapped bitset: ", bs, gapped );
	bench( "gapped vector: ", vb, gapped );
}

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

"Inside STL: The map, set, multimap, and multiset" by Raymond Chen Lynn McGuire <lynnmcguire5@gmail.com> - 2023-08-08 16:23 -0500
  Re: "Inside STL: The map, set, multimap, and multiset" by Raymond Chen wij <wyniijj5@gmail.com> - 2023-08-08 17:53 -0700
    Re: "Inside STL: The map, set, multimap, and multiset" by Raymond Chen Paavo Helde <eesnimi@osa.pri.ee> - 2023-08-09 09:26 +0300
      Re: "Inside STL: The map, set, multimap, and multiset" by Raymond Chen Öö Tiib <ootiib@hot.ee> - 2023-08-09 03:08 -0700
        Re: "Inside STL: The map, set, multimap, and multiset" by Raymond Chen Bonita Montero <Bonita.Montero@gmail.com> - 2023-08-09 13:22 +0200
        Re: "Inside STL: The map, set, multimap, and multiset" by Raymond Chen Bonita Montero <Bonita.Montero@gmail.com> - 2023-08-09 13:52 +0200
          Re: "Inside STL: The map, set, multimap, and multiset" by Raymond Chen Öö Tiib <ootiib@hot.ee> - 2023-08-09 05:10 -0700
            Re: "Inside STL: The map, set, multimap, and multiset" by Raymond Chen Bonita Montero <Bonita.Montero@gmail.com> - 2023-08-09 14:52 +0200
          Re: "Inside STL: The map, set, multimap, and multiset" by Raymond Chen wij <wyniijj5@gmail.com> - 2023-08-09 07:32 -0700
            Re: "Inside STL: The map, set, multimap, and multiset" by Raymond Chen Bonita Montero <Bonita.Montero@gmail.com> - 2023-08-09 16:36 +0200
      Re: "Inside STL: The map, set, multimap, and multiset" by Raymond Chen wij <wyniijj5@gmail.com> - 2023-08-09 07:20 -0700
        Re: "Inside STL: The map, set, multimap, and multiset" by Raymond Chen Paavo Helde <eesnimi@osa.pri.ee> - 2023-08-09 20:29 +0300
          Re: "Inside STL: The map, set, multimap, and multiset" by Raymond Chen Öö Tiib <ootiib@hot.ee> - 2023-08-09 21:09 -0700
  Re: "Inside STL: The map, set, multimap, and multiset" by Raymond Chen Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-08-15 08:37 -0700

csiph-web