Performance evaluation

For the sake of it, let's see how much performance we've actually gained. Here is a function that finds the distance to a specified point in a vector of randomly generated points:

// Generate 10000 random points 
auto points = std::vector<Point>{}; 
for(size_t i = 0; i < 10000; ++i) { 
  auto x = static_cast<float>(std::rand()); 
  auto y = static_cast<float>(std::rand()); 
  points.emplace_back(x, y); 
} 
// Find the distance to the nearest point 
auto needle = Point{135.0f, 246.0f};auto nearest_point = *std::min_element( 
  points.begin(),  
  points.end(),  
  [&needle](const Point& a, const Point& b) {    return a.distance(needle) < b.distance(needle);  });float dist = nearest_point.distance(needle);

Using DistProxy, this piece of code is executed ...

Get C++ High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.