Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

You mean you didn't *know* she was off making lots of little phone companies?


devel / comp.lang.c++ / What's this class good for ?

SubjectAuthor
* What's this class good for ?Bonita Montero
`* Re: What's this class good for ?Bonita Montero
 `- Re: What's this class good for ?Bonita Montero

1
What's this class good for ?

<uc589n$2vl7o$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1131&group=comp.lang.c%2B%2B#1131

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: What's this class good for ?
Date: Wed, 23 Aug 2023 17:23:36 +0200
Organization: A noiseless patient Spider
Lines: 89
Message-ID: <uc589n$2vl7o$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 23 Aug 2023 15:23:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8b1b1b4acfddfb487fd199c8bfd92750";
logging-data="3134712"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+bm63e+NRmRI6MupLSC1uuaJ7WDOglqqo="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:EpwFaI1T0y98vdRbUik5ylSfmbo=
Content-Language: de-DE
 by: Bonita Montero - Wed, 23 Aug 2023 15:23 UTC

#pragma once
#include <type_traits>
#include <concepts>
#include <new>
#include <utility>

template<typename T>
concept ndi_concept = std::is_trivial_v<T>;

template<ndi_concept T>
union ndi
{ ndi();
ndi( ndi const & );
ndi( T const &value );
ndi &operator =( T const &assign );
operator T &();
operator T const &() const;
T *operator &();
T const *operator &() const;
T *operator ->()
requires std::is_compound_v<T>;
T const *operator ->() const
requires std::is_compound_v<T>;
private:
T m_value;
};

template<ndi_concept T>
inline ndi<T>::ndi()
{ }

template<ndi_concept T>
inline ndi<T>::ndi( ndi const &other ) :
m_value( other.m_value )
{ }

template<ndi_concept T>
inline ndi<T>::ndi( T const &value )
{ m_value = value;
}

template<ndi_concept T>
inline ndi<T> & ndi<T>::operator =( T const &assign )
{ m_value = assign;
return *this;
}

template<ndi_concept T>
inline ndi<T>::operator T &()
{ return m_value;
}

template<ndi_concept T>
inline ndi<T>::operator T const &() const
{ return m_value;
}

template<ndi_concept T>
inline T *ndi<T>::operator &()
{ return &m_value;
}

template<ndi_concept T>
inline T const *ndi<T>::operator &() const
{ return &m_value;
}

template<ndi_concept T>
inline T *ndi<T>::operator ->()
requires std::is_compound_v<T>
{ return &m_value;
}

template<ndi_concept T>
inline T const *ndi<T>::operator ->() const
requires std::is_compound_v<T>
{ return &m_value;
}

Re: What's this class good for ?

<uc7j9u$3fhbh$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1146&group=comp.lang.c%2B%2B#1146

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What's this class good for ?
Date: Thu, 24 Aug 2023 14:43:43 +0200
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <uc7j9u$3fhbh$1@dont-email.me>
References: <uc589n$2vl7o$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 24 Aug 2023 12:43:42 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b01a33b29d39c87f910657740dee042d";
logging-data="3655025"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19qCQ+AV4kQLblyaY/iY0nI/eBL31hUoX0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:YT7sFG/Z1nG22x/FMbZmAb/akjM=
Content-Language: de-DE
In-Reply-To: <uc589n$2vl7o$1@dont-email.me>
 by: Bonita Montero - Thu, 24 Aug 2023 12:43 UTC

This class was to prevent default initialization of trivial types.
If you have a trivial type inside a vector and you resize the vector
the elements are default-initialized. If you chose to pre-reserve
the entitities of the vector and you do incremental emplace_back()s
the last-pointer would be updated repeatedly.

This code shows the performance difference:

#include <iostream>
#include <chrono>
#include <vector>
#include "ndi.h"

using namespace std;
using namespace chrono;

int main()
{ constexpr size_t N = 1'000'000'000;
auto bench = []( auto init, auto append, char const *what )
{
auto start = high_resolution_clock::now();
auto vec = init();
for( size_t i = 0; i != N; ++i )
append( vec, i );
cout << what << duration_cast<nanoseconds>(
high_resolution_clock::now() - start ).count() / 1.0e9 << endl;
};
bench( [&]() -> vector<ndi<int>>
{
return vector<ndi<int>>( N );
},
[&]( vector<ndi<int>> &vec, size_t i )
{
vec[i] = (int)i;
},
"vector<ndi<int>>: " );
bench( [&]() -> vector<int>
{
auto vec = vector<int>();
vec.reserve( N );
return vec;
},
[&]( vector<int> &vec, size_t i )
{
vec.emplace_back( (int)i );
},
"vector<int>: " );
}

With MSVC the ndi-variant has about 72% more throughput on my
AMD 7950X. With g++ on my AMD 3990X I get 63% more throughput.

Re: What's this class good for ?

<uc7k9k$3fm7p$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1147&group=comp.lang.c%2B%2B#1147

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!rocksolid2!news.neodome.net!weretis.net!feeder8.news.weretis.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: What's this class good for ?
Date: Thu, 24 Aug 2023 15:00:38 +0200
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <uc7k9k$3fm7p$1@dont-email.me>
References: <uc589n$2vl7o$1@dont-email.me> <uc7j9u$3fhbh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 24 Aug 2023 13:00:36 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b01a33b29d39c87f910657740dee042d";
logging-data="3660025"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/e/71eFWEXDMYQAoPHkIeDbQ0LmNGX6IE="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:+X23kIC4eTchrxfvCoDQLSknZiA=
Content-Language: de-DE
In-Reply-To: <uc7j9u$3fhbh$1@dont-email.me>
 by: Bonita Montero - Thu, 24 Aug 2023 13:00 UTC

If I touch all pages after reserving the vector with madvise()
/ MAP_POPULATE_WRITE I even get about 2,67 times the performance
on my AMD 3990X.

#include <iostream>
#include <chrono>
#include <vector>
#include "ndi.h"
#if defined(__unix__)
#include <sys/mman.h>
#endif

using namespace std;
using namespace chrono;

int main()
{ constexpr size_t N = (1ull << 30) / sizeof(int);
auto bench = []( auto init, auto append, char const *what )
{
auto start = high_resolution_clock::now();
auto vec = init();
for( size_t i = 0; i != N; ++i )
append( vec, i );
cout << what << duration_cast<nanoseconds>(
high_resolution_clock::now() - start ).count() / 1.0e9 << endl;
};
bench( [&]() -> vector<ndi<int>>
{
auto vec = vector<ndi<int>>( N );
#if defined(__unix__)
constexpr size_t PAGE_SIZE = 0x1000;
char
*begin = (char *)(((size_t)vec.data() + PAGE_SIZE - 1) &
-(ptrdiff_t)PAGE_SIZE),
*end = (char *)((size_t)(vec.data() + N) & -(ptrdiff_t)PAGE_SIZE);
if( end > begin && madvise( begin, end - begin, MADV_POPULATE_WRITE )
< 0 )
terminate();
#endif
return vec;
},
[&]( vector<ndi<int>> &vec, size_t i )
{
vec[i] = (int)i;
},
"vector<ndi<int>>: " );
bench( [&]() -> vector<int>
{
auto vec = vector<int>();
vec.reserve( N );
return vec;
},
[&]( vector<int> &vec, size_t i )
{
vec.emplace_back( (int)i );
},
"vector<int>: " );
}


devel / comp.lang.c++ / What's this class good for ?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor