Friday, March 19, 2021

Digest for comp.lang.c++@googlegroups.com - 19 updates in 3 topics

Bonita Montero <Bonita.Montero@gmail.com>: Mar 19 08:18AM +0100

So I just had the idea if the growth-overhead isn't really constant.
To check that I wrote this tiny test-program:
 
#include <iostream>
#include <vector>
#include <chrono>
 
using namespace std;
using namespace chrono;
 
int main()
{
using hrc_tp = time_point<high_resolution_clock>;
for( size_t n = (size_t)1 << 8; n <= (size_t)1 << 24; n *= 2 )
{
vector<size_t> vi;
hrc_tp start = high_resolution_clock::now();
for( size_t i = n; i; --i )
vi.emplace_back( i );
double ns = (double)(int64_t)duration_cast<nanoseconds>(
high_resolution_clock::now() - start ).count() / n;
cout << n << "\t" << ns << endl;
}
}
 
 
The results on my ThreadRipper 3990X are following:
 
256 31.56250
512 20.15620
1024 8.28125
2048 7.65625
4096 6.81641
8192 11.10350
16384 8.15430
32768 6.22803
65536 5.69458
131072 6.26465
262144 4.69452
524288 5.28549
1048576 3.97713
2097152 4.02081
4194304 4.27639
8388608 4.72761
16777216 3.93250
 
So the overhead is about to be constant with 32768 elements and further.
I'm aware that it is hard to ensure because the memory-allocator won't
have a linear behaviour.
 
Please post your results and tell the compiler- / standard-libary
-version !
MrSpook_Jo962q_c@3k5_1.biz: Mar 19 10:40AM

On Fri, 19 Mar 2021 08:18:06 +0100
> double ns = (double)(int64_t)duration_cast<nanoseconds>(
>high_resolution_clock::now() - start ).count() / n;
 
A triple cast? Seriously?
Paavo Helde <myfirstname@osa.pri.ee>: Mar 19 01:00PM +0200

19.03.2021 09:18 Bonita Montero kirjutas:
> have a linear behaviour.
 
> Please post your results and tell the compiler- / standard-libary
> -version !
 
MSVC2019 + tbbmalloc
 
256 383.594
512 17.3828
1024 13.0859
2048 7.08008
4096 6.56738
8192 6.26221
16384 4.03442
32768 4.76074
65536 4.80347
131072 3.35541
262144 4.07028
524288 5.70507
1048576 4.62179
2097152 4.47669
4194304 6.01001
8388608 7.32294
16777216 5.90116
Bonita Montero <Bonita.Montero@gmail.com>: Mar 19 01:00PM +0100

>> double ns = (double)(int64_t)duration_cast<nanoseconds>(
>> high_resolution_clock::now() - start ).count() / n;
 
> A triple cast? Seriously?
 
I do this because the x86-FPUs don't have load-instructions for unsigned
values. And further the compiler would complain that converting from an
int64_t to a double might drop information; having an explicit cast does
not cause such warnings.
Bonita Montero <Bonita.Montero@gmail.com>: Mar 19 01:07PM +0100

Look at this code ...
 
#include <cstdint>
 
using namespace std;
 
double f( uint64_t x )
{
return x;
}
 
It results in this ...
 
?f@@YAN_K@Z PROC ; f
; File C:\Users\Olli\x.cpp
; Line 7
xorps xmm0, xmm0
test rcx, rcx
js SHORT $LN3@f
cvtsi2sd xmm0, rcx
; Line 8
ret 0
$LN3@f:
; Line 7
mov rax, rcx
and ecx, 1
shr rax, 1
or rax, rcx
cvtsi2sd xmm0, rax
addsd xmm0, xmm0
; Line 8
ret 0
?f@@YAN_K@Z ENDP ; f
 
While this ...
 
#include <cstdint>
 
using namespace std;
 
double f( uint64_t x )
{
return (int64_t)x;
}
 
... results in this ...
 
?f@@YAN_K@Z PROC ; f
; File C:\Users\Olli\x.cpp
; Line 6
xorps xmm0, xmm0
; Line 7
cvtsi2sd xmm0, rcx
; Line 8
ret 0
?f@@YAN_K@Z ENDP ; f
Bonita Montero <Bonita.Montero@gmail.com>: Mar 19 01:16PM +0100

>> double ns = (double)(int64_t)duration_cast<nanoseconds>(
>> high_resolution_clock::now() - start ).count() / n;
 
> A triple cast? Seriously?
 
And if you want to really improve the above code to be perfect,
it would look like the following:
 
double ns = (double)(int64_t)duration_cast<nanoseconds>(
high_resolution_clock::now() - start ).count() / (ptrdiff_t)n;
 
I cast to ptrdiff_t because today it's safe to assume that it has the
same size like size_t, and ptrdiff_t is implicitly casted to double in
this statement, so I don't need an additioncal cast.
Ian Collins <ian-news@hotmail.com>: Mar 20 11:23AM +1300

On 20/03/2021 00:00, Paavo Helde wrote:
>> -version !
 
> MSVC2019 + tbbmalloc
 
> 256 383.594
 
Blimey!
 
> 4194304 6.01001
> 8388608 7.32294
> 16777216 5.90116
 
AMD Ryzen 7 2700X, Ubuntu clang version 13.0.0
 
256 13.1914
512 5.32227
1024 4.36426
2048 2.48486
4096 2.66382
8192 2.16602
16384 2.32263
32768 2.64426
65536 3.06087
131072 3.24371
262144 3.36548
524288 3.67879
1048576 4.68726
2097152 5.22924
4194304 4.80952
8388608 5.18689
16777216 5.08674
 
--
Ian.
Brian Wood <woodbrian77@gmail.com>: Mar 18 05:20PM -0700

On Saturday, May 11, 2019 at 12:28:33 AM UTC-5, Brian Wood wrote:
> Archimedes
> Jerusalem
> c-plus-plus
 
The C++ Middleware Writer merges two important areas: code
generation and services. By the grace of G-d and with your help,
I hope to improve on the areas above.
 
What do you think needs work? Thanks in advance.
 
 
Brian
Ebenezer Enteprises - Enjoying programming again.
https://webEbenezer.net
https://github.com/Ebenezer-group/onwards
Mr Flibble <flibble@i42.REMOVETHISBIT.co.uk>: Mar 19 01:05AM

On 19/03/2021 00:20, Brian Wood wrote:
> Ebenezer Enteprises - Enjoying programming again.
> https://webEbenezer.net
> https://github.com/Ebenezer-group/onwards
 
Give it a fucking rest, mate.
 
Best thing you can do right now is start a brand new unrelated project as this
project isn't going anywhere: the fact this isn't obvious to you after all this
time is depressing. YOU ARE WASTING YOUR TIME BY DOING FUCK ALL EXCEPT RELIGIOUS
PROSELYTISM ORIENTED PROCRASTINATION, OBVIOUS TO ALL AND SUNDRY.
 
/Flibble
 
--
😎
gazelle@shell.xmission.com (Kenny McCormack): Mar 19 01:56AM

In article <vNS4I.55821$ut29.21508@fx45.ams4>,
Mr Flibble <flibble@i42.REMOVETHISBIT.co.uk> wrote:
...
>you after all this time is depressing. YOU ARE WASTING YOUR TIME BY
>DOING FUCK ALL EXCEPT RELIGIOUS PROSELYTISM ORIENTED PROCRASTINATION,
>OBVIOUS TO ALL AND SUNDRY.
 
Could we all chip in to fund Brian and Rick's honeymoon?
 
If ever two people should just marry and ride off into the sunset, it is
these two.
 
--
You are a dreadful man, Kenny, for all your ways are the ways of death.
- Rick C Hodgin -
 
(P.S. -> https://www.youtube.com/watch?v=sMmTkKz60W8)
Brian Wood <woodbrian77@gmail.com>: Mar 18 06:57PM -0700

On Thursday, March 18, 2021 at 8:05:53 PM UTC-5, Mr Flibble wrote:
> > Ebenezer Enteprises - Enjoying programming again.
> > https://webEbenezer.net
> > https://github.com/Ebenezer-group/onwards
 
Don't swear here, please.
 
Sorry to disappoint you, but this is the way things
have to be now. One man's trash is another man's treasure ....
red floyd <no.spam.here@its.invalid>: Mar 19 12:28PM -0700

On 3/18/2021 6:57 PM, Brian Wood wrote:
 
 
> Don't swear here, please.
 
Fuck off. Who died and made you the ruler of c.l.c++?
Bonita Montero <Bonita.Montero@gmail.com>: Mar 19 08:21AM +0100

Is there a way to use literal-suffixes without selecting a namespace ?
F.e. "1std::s" doesn't work when I didn't say using chrono. Is there
something similar that would work ?
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 19 12:30PM +0100

On 19.03.2021 08:21, Bonita Montero wrote:
> Is there a way to use literal-suffixes without selecting a namespace ?
> F.e. "1std::s" doesn't work when I didn't say using chrono. Is there
> something similar that would work ?
 
Just
 
using namespace std::literals;
 
and be done with it. ;-)
 
- Alf
Bonita Montero <Bonita.Montero@gmail.com>: Mar 19 02:06PM +0100


> Just
>     using namespace std::literals;
> and be done with it. ;-)
 
As you can imagine I'm already aware of that.
But that's not what I asked for.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 19 05:19PM +0100

On 19.03.2021 14:06, Bonita Montero wrote:
>> and be done with it. ;-)
 
> As you can imagine I'm already aware of that.
> But that's not what I asked for.
 
You could call the operator like a function, e.g.
 
std::literals::operator""s( "Blah" )
 
You could even create a local synonym:
 
auto s( const char* const s )
-> string
{ return std::literals::operator""s( s ); }
 
Using string literal example because I'm not so familiar with chrono.
 
Disclaimer: off the cuff code, not touched by compilers' dirty hands.
 
- Alf
Bonita Montero <Bonita.Montero@gmail.com>: Mar 19 06:49PM +0100

>     { return std::literals::operator""s( s ); }
> Using string literal example because I'm not so familiar with chrono.
> Disclaimer: off the cuff code, not touched by compilers' dirty hands.
 
As my question suggests I was asking for a nearly as convenient solution
than the example I gave, i.e. 1std::s f.e..
Juha Nieminen <nospam@thanks.invalid>: Mar 19 07:02PM

> Is there a way to use literal-suffixes without selecting a namespace ?
> F.e. "1std::s" doesn't work when I didn't say using chrono. Is there
> something similar that would work ?
 
While the suffixes are cool and all, I myself just prefer to write eg.
 
std::chrono::seconds(123)
 
Sure, it's longer, but a lot easier to read and understand at a
quick glance.
Bonita Montero <Bonita.Montero@gmail.com>: Mar 19 08:14PM +0100

> std::chrono::seconds(123)
> Sure, it's longer, but a lot easier to read and understand at a
> quick glance.
 
I always select the std::/chrono::-namespaces in my .cpp-file globally.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: