|
Boost : |
From: Bruno Lalande (bruno.lalande_at_[hidden])
Date: 2008-03-27 17:20:14
> I have 10^9 x,y values as doubles give me the convex hull - can you
> imagine in the overhead if each of those pairs were to be converted to a
> point_concept/class/instance?
If you speak about an algorithm like the convex hull, maybe you're
right. If you speak about more simple ones like distance, so long as
the compiler optimizes correctly and the programmer provides an
inlinable point class, chances are that the code compiled will be
quite the same. Example:
inline double dist(double x1, double y1, double x2, double y2)
{
double dx = x2 - x1;
double dy = y2 - y1;
return sqrt(dx*dx + dy*dy);
}
struct point
{
point(double x_, double y_):
x(x_), y(y_)
{}
double x;
double y;
};
inline double dist(const point& p1, const point& p2)
{
double dx = p2.x - p1.x;
double dy = p2.y - p1.y;
return sqrt(dx*dx + dy*dy);
}
On my computer with GCC -O3, this:
dist(a, b, c, d);
runs exactly as fast as this:
dist(point(a, b), point(c, d));
and I'm pretty sure the compiled code is more or less the same.
Usually I'm not really fan of decomposing each function that acts on
points into the same function acting on their components. It usually
ends up in endless series of overloads (even when sticking to 2D). So
it should be reserved only to those functions for which the overhead
is real.
Bruno
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk