Class PerformanceTests

java.lang.Object
org.djutils.complex.demo.PerformanceTests

public final class PerformanceTests extends Object
PerformanceTests.java.

Copyright (c) 2020-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.
Author:
Alexander Verbraeck, Peter Knoppers
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    hypotA(double px, double py)
    Implementation of hypot taken from https://stackoverflow.com/questions/3764978/why-hypot-function-is-so-slow .
    static double
    hypotB(double px, double py)
    hypot.
    static double
    hypotC(double x, double y)
    Better implementation of the hypotenuse function (faster and more accurate than the one in the java Math library).
    static void
    main(String[] args)
    Measure performance of atan2, hypot, sine and cosine.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • main

      public static void main(String[] args)
      Measure performance of atan2, hypot, sine and cosine.
      Parameters:
      args - String[]; the command line arguments (not used)
    • hypotA

      public static double hypotA(double px, double py)
      Implementation of hypot taken from https://stackoverflow.com/questions/3764978/why-hypot-function-is-so-slow .
      Parameters:
      px - double; x
      py - double; y
      Returns:
      double; the hypot of x, and y
    • hypotB

      public static double hypotB(double px, double py)
      hypot.
      Parameters:
      px - double; x
      py - double; y
      Returns:
      sqrt(x*x +y*y) without intermediate overflow or underflow. Note Math.hypot(double, double) is unnecessarily slow. This returns the identical result to Math.hypot with reasonable run times (~40 nsec vs. 800 nsec). The logic for computing z is copied from "Freely Distributable Math Library" fdlibm's e_hypot.c. This minimizes rounding error to provide 1 ulb accuracy.
    • hypotC

      public static double hypotC(double x, double y)
      Better implementation of the hypotenuse function (faster and more accurate than the one in the java Math library).
      Derived from An improved algorithm for hypot(a, b) by Carlos F. Borges.
      Parameters:
      x - double; the x value
      y - double; the y value
      Returns:
      double; hypot(x, y)