Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

19 May, 2024: Line wrapping has been changed to be more consistent with Usenet standards.
 If you find that it is broken please let me know here rocksolid.nodes.help


devel / comp.lang.c++ / Re: reverse iteration is slower !

SubjectAuthor
* reverse iteration is slower !Bonita Montero
`* Re: reverse iteration is slower !Chris M. Thomasson
 `* Re: reverse iteration is slower !Bonita Montero
  `* Re: reverse iteration is slower !Chris M. Thomasson
   `* Re: reverse iteration is slower !Bonita Montero
    `- Re: reverse iteration is slower !Chris M. Thomasson

1
reverse iteration is slower !

<v158ve$16jpo$1@raubtier-asyl.eternal-september.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: reverse iteration is slower !
Date: Sat, 4 May 2024 14:16:47 +0200
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <v158ve$16jpo$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 04 May 2024 14:16:46 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="3e911164b3298ab89e1e629b26ef2914";
logging-data="1265464"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9f8UJ/6urcH/fGz+k/htk99hlUGGeTjI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Y+Dkrn/Uy6v6oesiZDmUzzTSmAM=
Content-Language: de-DE
 by: Bonita Montero - Sat, 4 May 2024 12:16 UTC

With a vector a reverse iterator is derived from the normal iterator
and accesses with an offset of -1. With today's CPUs this isn't slower.
I wondered if the performance is still the same with ordered maps or
sets, where this would mean a real penalty since offsetting is done
twice, once for the access and once for iteration to the next element.
So I wrote a small benchmark for that:

#include <iostream>
#include <set>
#include <chrono>
#include <atomic>

using namespace std;
using namespace chrono;

atomic_int aSum;

int main()
{ set<int> st;
for( int i = 0; i != 100; ++i )
st.emplace( i );
auto timeLoop = []( char const *what, auto fn )
{
auto start = high_resolution_clock::now();
int sum = 0;
for( size_t i = 1'000'000; i; --i )
fn( sum );
cout << what << duration_cast<nanoseconds>(
high_resolution_clock::now() - start ).count() / 100e6 << endl;
::aSum.store( sum, memory_order_relaxed );
};
timeLoop( "forward: ",
[&]( int &sum )
{
for( auto it = st.begin(); it != st.end(); ++it )
sum += *it;
} );
timeLoop( "reverse: ",
[&]( int &sum )
{
for( auto it = st.rbegin(); it != st.rend(); ++it )
sum += *it;
} );
timeLoop( "manual reverse: ",
[&]( int &sum )
{
for( auto it = st.end(); it != st.begin(); )
sum += *--it;
} );
}

This is the result with MSVC++ 18 on a 5.7GHz Zen4-CPU.

forward: 1.70247
reverse: 2.05701
manual reverse: 1.77813

The first result is from the bidirectional iterator, the second from the
reverse-iterator and the third from a bidirectional iterator iterating
reverse.
So iterate reverse only if necessary.

Re: reverse iteration is slower !

<v163si$1cg4b$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: reverse iteration is slower !
Date: Sat, 4 May 2024 12:56:02 -0700
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <v163si$1cg4b$1@dont-email.me>
References: <v158ve$16jpo$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 04 May 2024 21:56:03 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="00566bb81b0a3452542610785f934900";
logging-data="1458315"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18m975F+FodPpfzxoMDum9WPKjOUvrU/+0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ozr8qRD7Bijuo9ZGbi+LFJ4Y1sA=
Content-Language: en-US
In-Reply-To: <v158ve$16jpo$1@raubtier-asyl.eternal-september.org>
 by: Chris M. Thomasson - Sat, 4 May 2024 19:56 UTC

On 5/4/2024 5:16 AM, Bonita Montero wrote:
> With a vector a reverse iterator is derived from the normal iterator
> and accesses with an offset of -1. With today's CPUs this isn't slower.
> I wondered if the performance is still the same with ordered maps or
> sets, where this would mean a real penalty since offsetting is done
> twice, once for the access and once for iteration to the next element.
> So I wrote a small benchmark for that:
[...]

Cache lines like to be read, going forward, perhaps a prefetch is in
order... ;^)

Re: reverse iteration is slower !

<v16582$1cpup$1@raubtier-asyl.eternal-september.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: reverse iteration is slower !
Date: Sat, 4 May 2024 22:19:16 +0200
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <v16582$1cpup$1@raubtier-asyl.eternal-september.org>
References: <v158ve$16jpo$1@raubtier-asyl.eternal-september.org>
<v163si$1cg4b$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 04 May 2024 22:19:15 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="3e911164b3298ab89e1e629b26ef2914";
logging-data="1468377"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/UevR7IRz/0mZi9qNR5DQhtu648TI0cGA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:CeF7g0BrkVpGD38AEb/jFKSlJUg=
Content-Language: de-DE
In-Reply-To: <v163si$1cg4b$1@dont-email.me>
 by: Bonita Montero - Sat, 4 May 2024 20:19 UTC

Am 04.05.2024 um 21:56 schrieb Chris M. Thomasson:
> On 5/4/2024 5:16 AM, Bonita Montero wrote:
>> With a vector a reverse iterator is derived from the normal iterator
>> and accesses with an offset of -1. With today's CPUs this isn't slower.
>> I wondered if the performance is still the same with ordered maps or
>> sets, where this would mean a real penalty since offsetting is done
>> twice, once for the access and once for iteration to the next element.
>> So I wrote a small benchmark for that:
> [...]
>
> Cache lines like to be read, going forward, perhaps a prefetch is in
> order... ;^)
>

Theres's no specific phyisal access order with a set or map.

Re: reverse iteration is slower !

<v16619$1ctj7$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: reverse iteration is slower !
Date: Sat, 4 May 2024 13:32:42 -0700
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <v16619$1ctj7$1@dont-email.me>
References: <v158ve$16jpo$1@raubtier-asyl.eternal-september.org>
<v163si$1cg4b$1@dont-email.me>
<v16582$1cpup$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 04 May 2024 22:32:42 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="00566bb81b0a3452542610785f934900";
logging-data="1472103"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/UOuM0SntCHInmi5OtaBVtm3++l7+lgcY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:qz1Tg3jJEO6qGs3AQ3d+Ih4nc94=
In-Reply-To: <v16582$1cpup$1@raubtier-asyl.eternal-september.org>
Content-Language: en-US
 by: Chris M. Thomasson - Sat, 4 May 2024 20:32 UTC

On 5/4/2024 1:19 PM, Bonita Montero wrote:
> Am 04.05.2024 um 21:56 schrieb Chris M. Thomasson:
>> On 5/4/2024 5:16 AM, Bonita Montero wrote:
>>> With a vector a reverse iterator is derived from the normal iterator
>>> and accesses with an offset of -1. With today's CPUs this isn't slower.
>>> I wondered if the performance is still the same with ordered maps or
>>> sets, where this would mean a real penalty since offsetting is done
>>> twice, once for the access and once for iteration to the next element.
>>> So I wrote a small benchmark for that:
>> [...]
>>
>> Cache lines like to be read, going forward, perhaps a prefetch is in
>> order... ;^)
>>
>
> Theres's no specific phyisal access order with a set or map.
>

It depends on the implementation. Is this a generic set or map, or a
very highly specialized one that only works well with certain inputs...

Re: reverse iteration is slower !

<v16uhj$1ldu6$1@raubtier-asyl.eternal-september.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: reverse iteration is slower !
Date: Sun, 5 May 2024 05:31:01 +0200
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <v16uhj$1ldu6$1@raubtier-asyl.eternal-september.org>
References: <v158ve$16jpo$1@raubtier-asyl.eternal-september.org>
<v163si$1cg4b$1@dont-email.me>
<v16582$1cpup$1@raubtier-asyl.eternal-september.org>
<v16619$1ctj7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 05 May 2024 05:31:00 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="555a89add3c6d55a0fec68f4f17405c5";
logging-data="1750982"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fTvkBNvz/ftpALCmFtv5qHc04JKrDYQM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:iD9qTM4bq0D7Zpb8hnQbFUBlAyM=
In-Reply-To: <v16619$1ctj7$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Sun, 5 May 2024 03:31 UTC

Am 04.05.2024 um 22:32 schrieb Chris M. Thomasson:

> It depends on the implementation. ...

There's nothing to prefetch in a tree.

Re: reverse iteration is slower !

<v174v8$1mg25$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: reverse iteration is slower !
Date: Sat, 4 May 2024 22:20:40 -0700
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <v174v8$1mg25$1@dont-email.me>
References: <v158ve$16jpo$1@raubtier-asyl.eternal-september.org>
<v163si$1cg4b$1@dont-email.me>
<v16582$1cpup$1@raubtier-asyl.eternal-september.org>
<v16619$1ctj7$1@dont-email.me>
<v16uhj$1ldu6$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 05 May 2024 07:20:41 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="4cb66168bb732a9923ed8af7e043800c";
logging-data="1785925"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/r4dtkECHfhMTLLKRahi79lZXmhn+2bQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:CECsRH5d7nseBt45g+VUhIE76m0=
Content-Language: en-US
In-Reply-To: <v16uhj$1ldu6$1@raubtier-asyl.eternal-september.org>
 by: Chris M. Thomasson - Sun, 5 May 2024 05:20 UTC

On 5/4/2024 8:31 PM, Bonita Montero wrote:
> Am 04.05.2024 um 22:32 schrieb Chris M. Thomasson:
>
>> It depends on the implementation. ...
>
> There's nothing to prefetch in a tree.
>
>

Nevermind.


devel / comp.lang.c++ / Re: reverse iteration is slower !

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor