Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8308777

Math.{ceil,floor,rint,sin,cos} are slower than their StrictMath version on linux-x64

    XMLWordPrintable

Details

    • x86_64
    • linux

    Description

      The classjava.lang.Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. The numeric methods of class java.lang.StrictMath are defined to return the bit-for-bit same results on all platforms. The implementations of the equivalent functions in class java.lang.Math do not have this requirement. This relaxation permits better-performing implementations where strict reproducibility is not required. By default most of the java.lang.Math methods simply call the equivalent method in java.lang.StrictMath for their implementation. Code generators (like C2) are encouraged to use platform-specific native libraries or microprocessor instructions, where available, to provide higher-performance implementations of java.lang.Math methods. Such higher-performance implementations still must conform to the specification for java.lang.Math

      Running JMH benchmarks shows Math.{ceil,floor,rint,sin,cos} are slower than StrictMath.{ceil,floor,rint,sin,cos} on linux-x64

      To reproduce:
      cp BenchmarkMath.java test/micro
      CONF=linux-x64 make build-microbenchmark
      CONF=linux-x64 make TEST="micro:BenchmarkMath"

      Benchmark Mode Cnt Score Error Units
      Math.ceil thrpt 5 294595.000 ± 773.099 ops/ms
      StrictMath.ceil thrpt 5 389087.943 ± 499.688 ops/ms
      Math.floor thrpt 5 293216.581 ± 1237.387 ops/ms
      StrictMath.floor thrpt 5 550274.637 ± 4338.825 ops/ms
      Math.rint thrpt 5 293165.619 ± 429.784 ops/ms
      StrictMath.rint thrpt 5 551528.253 ± 2359.219 ops/ms
      Math.sin thrpt 5 59070.345 ± 286.291 ops/ms
      StrictMath.sin thrpt 5 60902.089 ± 281.070 ops/ms
      Math.cos thrpt 5 59491.008 ± 463.730 ops/ms
      StrictMath.cos thrpt 5 65376.387 ± 273.728 ops/ms

      Attachments

        Activity

          People

            Unassigned Unassigned
            tholenstein Tobias Holenstein
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: