Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Java math performs better with Jdk1.6 ea-19  (Read 1451 times)
0 Members and 1 Guest are viewing this topic.
Offline arm

Senior Newbie




Java games rock!


« Posted 2005-01-19 12: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

Senior Member




Friendly fire isn't friendly!


« Reply #1 - Posted 2005-01-19 15:59:50 »

Seems that Math is no longer implicitely strict  Wink Cheesy

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (40 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!