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

double & int ops performance regression

XMLWordPrintable

    • b80
    • x86
    • windows_xp

      A DESCRIPTION OF THE REGRESSION :
       There are regressions on doubles and ints expressions.


      REPRODUCIBLE TESTCASE OR STEPS TO REPRODUCE:
      import java.io.*;


      public class Speed
      {
          static class Evaluator
          {
             public final double eval(double i)
              { return (i * 0.123456) / (i + 1.0); }
          }
          
          Object obj; // used for isA tests
          static double r;

          public static void main(String[] args)
          { Speed sp = new Speed(args); }

          public Speed(String[] args)
          {
              obj = this;
              int ns = args.length;
              int niters = 3;
              for (int i = 0; i < ns; i++)
              {
                  try
                  {
                      niters = Integer.parseInt(args[i]);
                  } catch (Exception ex)
                  {}
              }
              run(niters);
          }

          static void printTime(String mes, long time, double v)
          {
              System.out.print(" Testing " + mes + " : ");
              System.out.println( (time / 1000.0) + " s.");
              if (v > 0.0)
                  System.out.println(" result = " + v);
              System.out.println();
          }

          public void run(int idx)
          {
              final int ncycle = idx;
              long start = System.currentTimeMillis();
              int k, i, n = (int) 1E7;
              for (k = 1; k <= ncycle; k++)
              {
                  System.out.println();
                  System.out.println(" --------------------------" + Integer.toString(k)
                          + "--------------------------------");
                  System.out.println();
                  System.out.println();
                  
                  long iter_time = 0 ;
                  // Test # 2
                  iter_time += testDoubleOpsViaFunctionCall((int) 1E8);
                  // Test # 3
                  iter_time += testInlinedDoubleOps((int) 1E8);
                  // Test # 4
                  iter_time += testIntOperations((int) 1E9);

              }
          }

          // double operation with function call
          long testDoubleOpsViaFunctionCall(int n)
          {
              double r = 0.0;
              Evaluator evaluator = new Evaluator();
              long start = System.currentTimeMillis();
              for (int i = 1; i <= n; i++)
                  r += evaluator.eval((double) i);
              long time = System.currentTimeMillis() - start ;
              printTime (n + " double moltiplications via function call", time, r);
              return time ;
          }

          // Test # 3 -B
          long testInlinedDoubleOps(int n)
          {
              int i;
              double r = 0.0;

              long start = System.currentTimeMillis();
              for (i = 1; i <= n; i++)
                  r += (i * 0.123456) / (i + 1.0);
              long time = System.currentTimeMillis() - start;
              printTime(n + " inlined double moltiplications", time, r);
              return time ;
          }

          long testIntOperations(int n)
          {
              int i, a = 0, b = 2;
              long start = System.currentTimeMillis();
              for (i = 1; i <= n; i++)
                  a += a - i * 3;
              long time = System.currentTimeMillis() - start;
              printTime(n + " int moltiplications + additions", time,
                      (double) a);
              return time ;
          }

      }


      RELEASE LAST WORKED:
      5.0 Update 6

      RELEASE TEST FAILS:
      mustang-beta

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Java HotSpot(TM) Server VM (build 1.5.0_06-b05, mixed mode)

      After several warm-up iterations ...

          Testing 100000000 double moltiplications via function call : 1.437
            result = 1.2345597781357473E7

          Testing 100000000 inlined double moltiplications : 1.453 s.
            result = 1.2345597781357473E7

          Testing 1000000000 int moltiplications + additions : 0.969 s.
      ACTUAL -

      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-beta2-b73)
      Java HotSpot(TM) Server VM (build 1.6.0-beta2-b73, mixed mode)

      After several warm-up iterations ...

       Testing 100000000 double moltiplications via function call : 1.765 s.
         result = 1.2345597781357473E7

       Testing 100000000 inlined double moltiplications : 1.766 s.
         result = 1.2345597781357473E7

       Testing 1000000000 int moltiplications + additions : 2.172 s.

      Release Regression From : 5.0u6
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

            rasbold Chuck Rasbold
            collins Gary Collins (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: