Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #87267
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: What is this header good for ? |
| Date | 2022-11-06 10:34 +0100 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <tk7v2o$evi$1@gioia.aioe.org> (permalink) |
| References | (8 earlier) <c061094f-7064-4913-a547-1a2ffa4d84e5n@googlegroups.com> <tk5t95$2gncr$1@dont-email.me> <9268ea98-1e79-492a-8f78-6ab52005a441n@googlegroups.com> <tk65g1$2ik4v$1@dont-email.me> <26dcb12b-18e1-4eca-8a12-85dd4ac414d7n@googlegroups.com> |
I've written a little program to demonstrate the advantage of my ndi_t
union:
#include <iostream>
#include <vector>
#include <chrono>
#include <cmath>
#include <sstream>
#include "ndi_t.h"
using namespace std;
using namespace chrono;
int main()
{
auto bench = []<typename T, typename Touch>( T t, Touch touch ) -> double
requires requires( Touch touch, vector<T> &vt ) { { touch( vt ) }; }
{
constexpr size_t N = (size_t)1 << 30;
vector<T> vt;
auto start = high_resolution_clock::now();
vt.resize( N );
touch( vt );
return (double)duration_cast<nanoseconds>(high_resolution_clock::now()
- start).count() / 1.0e6;
};
auto ndiTouch = []( vector<ndi_t<char>> &ndiVec )
{
for( size_t i = 0; i < ndiVec.size(); ndiVec[i] = 0, i += 0x1000 );
};
double
tChar = bench( char(), []( vector<char> const & ) {} ),
tNdi = bench( ndi_t<char>(), []( vector<ndi_t<char>> const & ) {} ),
tNdiTouch = bench( ndi_t<char>(), ndiTouch );
cout << "char: " << tChar << "ms" << endl;
cout << "ndi_t<char>: " << tNdi << "ms" << endl;
cout << "ndi_t<char> (touch): " << tNdiTouch << "ms" << endl;
}
It benchmarks the time to resize a char-vector to one GB. My ndi_t
union is about 30.000 times faster on my Linux computer. This is
while such large allocations aren't pooled by your memory allocator
but directly fetched from the kernel in multiples of pages. If this
pages aren't touched they remain unassigned to actual physical memory.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
What is this header good for ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-01 15:32 +0100
Re: What is this header good for ? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-11-01 20:23 +0100
Re: What is this header good for ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-02 03:59 +0100
Re: What is this header good for ? Tony Oliver <guinness.tony@gmail.com> - 2022-11-02 04:45 -0700
Re: What is this header good for ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-02 14:33 +0100
Re: What is this header good for ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-02 04:02 +0100
Re: What is this header good for ? Muttley@dastardlyhq.com - 2022-11-02 16:59 +0000
Re: What is this header good for ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-02 18:45 +0100
Re: What is this header good for ? Öö Tiib <ootiib@hot.ee> - 2022-11-03 08:22 -0700
Re: What is this header good for ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-03 16:43 +0100
Re: What is this header good for ? Öö Tiib <ootiib@hot.ee> - 2022-11-03 09:06 -0700
Re: What is this header good for ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-04 20:12 +0100
Re: What is this header good for ? Öö Tiib <ootiib@hot.ee> - 2022-11-05 06:24 -0700
Re: What is this header good for ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-05 15:51 +0100
Re: What is this header good for ? Öö Tiib <ootiib@hot.ee> - 2022-11-05 09:44 -0700
Re: What is this header good for ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-05 18:11 +0100
Re: What is this header good for ? Öö Tiib <ootiib@hot.ee> - 2022-11-05 16:03 -0700
Re: What is this header good for ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-06 06:19 +0100
Re: What is this header good for ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-06 10:34 +0100
csiph-web