------------------------C++ Benchmark------------------------------- #include #include #include class Point{ double a[3]; public: Point(double x, double y, double z) {a[0] = x, a[1] = y; a[2] = z;} const double& x() const { return a[0];} const double& y() const { return a[1];} const double& z() const { return a[2];} bool coincident(const Point& a, double eps) const; }; bool Point::coincident(const Point& a, double eps) const { return fabs(x()-a.x()) < eps && fabs(y()-a.y()) < eps && fabs(z()-a.z()) < eps; } bool test(const Point& a, const Point& b) { return a.coincident(b, 1e-5); } int main() { time_t start = time(0); Point a(10.0,10.0,20.0); Point b(10.0,10.0,20.0); for (int i = 0; i < 10000000; ++i) { test(a,b); } cout << time(0) - start << endl; } -----------------------Java------------------------------------- public class Point extends Object { double a[] = new double[3]; public Point(double x, double y, double z) { a[0] = x; a[1] = y; a[2] = z; } public double x() { return a[0]; } public double y() { return a[1]; } public double z() { return a[2]; } boolean coincident(Point a, double eps) { return Math.abs(x()-a.x()) < eps && Math.abs(y()-a.y()) < eps && Math.abs(z()-a.z()) < eps; } public static void main(String args[]) { Point a = new Point(10.0,10.0,20.0); Point b = new Point(10.0,10.0,20.0); long start = System.currentTimeMillis(); for (int i = 0; i < 10000000; ++i) { test(a,b); } System.out.println(System.currentTimeMillis()-start); } public static boolean test(Point a, Point b) { return a.coincident(b, 1e-5); } }