[libcxx-commits] [PATCH] D71525: [libc++] Fix typo in std::midpoint
Ruslan Baratov via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Dec 16 00:23:30 PST 2019
ruslo added a comment.
> there is no visible error because the difference is between (a/2 + b/2) and (a/2 + b) when (a > hi && b < lo)
You can see the difference if you run the benchmark:
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
double midpoint_sum(const vector<double>& v1, const vector<double>& v2) {
double res{0.0};
for (size_t i = 0; i < v1.size(); ++i) {
res += midpoint(v1[i], v2[i]);
}
return res;
}
template <class T>
void print_duration(T start, T end) {
auto diff = end - start;
cout << chrono::duration_cast<chrono::milliseconds>(diff).count() << " ms\n";
}
int main() {
using clock = chrono::high_resolution_clock;
size_t n = 500 * 1000 * 1000;
double a = numeric_limits<double>::min() * 1.99; // a < lo
double b = numeric_limits<double>::max() / 1.99; // b > hi
vector<double> v_a(n, a);
vector<double> v_b(n, b);
auto start = clock::now();
double r_a = midpoint_sum(v_a, v_b);
auto end = clock::now();
print_duration(start, end);
start = clock::now();
double r_b = midpoint_sum(v_b, v_a);
end = clock::now();
print_duration(start, end);
// Use results
cout << "Result: " << r_a << '\n';
cout << "Result: " << r_b << '\n';
}
Original libc++:
1388 ms
21910 ms
Patched libc++:
1390 ms
1393 ms
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D71525/new/
https://reviews.llvm.org/D71525
More information about the libcxx-commits
mailing list