Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Java math performs better with Jdk1.6 ea-19  (Read 1064 times)
0 Members and 2 Guests are viewing this topic.
Offline arm

JGO n00b
*

Posts: 13


Java games rock!


« on: 2005-01-19 07:23:21 »

Test code excerpted from
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6206844



public class mtest
{
 static int ops0;
 static int ops1;
 static int ops2;

 static double DVAL = 13.d;
 static float  FVAL = 13.f;
 static final int LIMIT = 20000000;

 static volatile long L = 0L;

 static long checkVolatileUse()
 {
   L += 32L;
   return L; // L still live here
 }

 static int checkDoubleOps(double dval)
 {
     //modD
     double d1 = dval % DVAL;
     //ConvD2F
     float  f1 = (float)d1;
     //modF
     float  f2 = f1 % FVAL;
     //ConvF2D
     double d2 = (double)f2;
     //sinD
     d1 = Math.sin(d2);
     d2 = d1 * DVAL;
     double res = d1 + d2 ;
     //cosD
     d1 = Math.cos(d2);
     d2 = d1 / DVAL;
     res += d1;
     res += d2;
     
     //tanD
     d1 = Math.tan(d2);
     d2 = DVAL - d1;
     res += d1;
     res += d2;
     //logD
     d1 = Math.log(d2);
     d2 = d1 + DVAL;
     res += d1;
     res += d2;
     //log10D
     //d1 = Math.log10(d2); log10 doesn't exist in  1.4
     res += d1;
     res += d2;
     //ConvL2D
     long l = (long) res;
     //ConvL2F
     l += (long)f1;
     return (int)l;
 }

 static int checkLong2Double (double d)
 {
     long longbits = Double.doubleToRawLongBits(d);
     double d2 = Double.longBitsToDouble(longbits);
     if (d != d2) {
       throw new InternalError("value mismatch");
     }
     long longbits2 = Double.doubleToRawLongBits(d2);
     if (longbits != longbits2) {
       throw new InternalError("value mismatch");
     }

     float f = (float) d;
     int intbits = Float.floatToRawIntBits(f);
     float f2 = Float.intBitsToFloat(intbits);
     if (f != f2) {
       throw new InternalError("value mismatch");
     }
     int intbits2 = Float.floatToRawIntBits(f2);
     if (intbits != intbits2) {
       throw new InternalError("value mismatch");
     }
     return intbits2;
 }

 static int testVolatileUse(int limit) {
   int i = 0;
   L = 0;
   for (ops0 = 0; ops0 < limit; ops0++) {
     i += (int)checkVolatileUse();
   }
   return i;
 }
 static int testDoubleOps(double d, int limit) {
   int i = 0;
   for (ops1 = 0; ops1 < limit; ops1++) {
     i += checkDoubleOps(d);
   }
   return i;
 }

 static int testLongDoubleConversion(double d, int limit) {
   int i = 0;
   for (ops2 = 0; ops2 < limit; ops2++) {
     i += checkLong2Double(d);
   }
   return i;
 }

 public static void main(String[] args)
 {
   double d = 0.0123456789d;
   int i = testVolatileUse(11000);     // warmup
   i = testVolatileUse(10000);         // warmup
   i = testLongDoubleConversion(d, 11000);      // warmup
   i = testLongDoubleConversion(d, 10000);      // warmup
   i = testDoubleOps(d, 11000);      // warmup
   i = testDoubleOps(d, 10000);      // warmup

   long s = System.currentTimeMillis ();
   i = testVolatileUse(LIMIT);  // run
   long t = System.currentTimeMillis() - s ;
   double seconds = ( t / 1000.0);
     System.out.println(" volatile long: " + (int) (ops0 / seconds) + " loops per second. " + i);

   s = System.currentTimeMillis ();
   i = testLongDoubleConversion(d, LIMIT);  // run
   t = System.currentTimeMillis() - s ;
   seconds = ( t / 1000.0);
     System.out.println("raw 64 bits : " + (int)(ops2 / seconds) + " loops per second. " + i);

   s = System.currentTimeMillis ();
   i = testDoubleOps(d, LIMIT);  // run
   t = System.currentTimeMillis() - s ;
   seconds = ( t / 1000.0);
   System.out.println("math on FPU : " + (int) (ops1 / seconds) + " loops per second. " + i);
 }
}


Results on Pentium 4 2.8 Ghz, 1G RAM:



Java HotSpot(TM) Server VM (build 1.6.0-ea-b19, mixed mode)

volatile long: 60790273 loops per second. 832753664
raw 64 bits : 2147483647 loops per second. -448731136
math on FPU : 2475860 loops per second. 1000000000

Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Server VM (build 1.5.0-b64, mixed mode)

   volatile long: 18814675 loops per second. 832753664
   raw 64 bits : 2147483647 loops per second. -448731136
  math on FPU : 550070 loops per second. 1000000000


Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2)
Classic VM (build 1.4.2, J2RE 1.4.2 IBM Windows 32 build cn1420-20040626 (JIT enabled: jitc))

      volatile long: 183486238 loops per second. 832753664
      raw 64 bits : 5688282 loops per second. -448731136
      math on FPU : 1921968 loops per second. 1000000000

           Ciao





Offline Herkules

JGO Kernel
*****

Posts: 1522
Medals: 1


Friendly fire isn't friendly!


« Reply #1 on: 2005-01-19 10:59:50 »

Seems that Math is no longer implicitely strict  Wink Cheesy

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.071 seconds with 19 queries.