Skip to content

Commit

Permalink
Updating.
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed Dec 1, 2022
1 parent 1a1439a commit c5ca5e5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 2012/06/20/modern_testvectorcpp11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ vector<C> runtestnicewreserve(size_t N) {
return bigarray;
}

template <class C>
__attribute__((noinline))
vector<C> runtestnicewresize(size_t N) {
vector<C> bigarray;
bigarray.resize(N);
for (unsigned int k = 0; k < N; ++k)
bigarray[k] = k;
return bigarray;
}



template <class C>
Expand Down Expand Up @@ -186,6 +196,22 @@ template <class C> void demo() {

x = 1e300;
y = 0;
for (size_t i = 0; i < trials; i++) {
time.start();
auto z = runtestnicewresize<C>(N);
auto result = time.stop() * 1.0 / N;
y += result;
if (result < x) {
x = result;
}
hole = z[0];
}
y = y / trials;
cout << "with resize and [] : " << x << " (" << (y - x) * 100 / x
<< " %)" << endl;

x = 1e300;
y = 0;

for (size_t i = 0; i < trials; i++) {
time.start();
Expand Down

0 comments on commit c5ca5e5

Please sign in to comment.