Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  Fastest get2fold algorithm  (Read 7672 times)
0 Members and 1 Guest are viewing this topic.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #30 - Posted 2006-04-03 18:48:19 »

Ouch. System.currentTimeMillis() is way to inaccurate for benchmark-results under 100ms (as it might snap to 15ms values).

Java 1.4 has sun.misc.Perf to do what System.nanoTime does in 1.5+

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline DzzD
« Reply #31 - Posted 2006-04-03 19:20:10 »

it is true that System.currentTimeMillis() can have about 16ms error, but, if the complete test is lasting enough time,the final result will have a very good precision.

example: if the full loop lasts more than 5 seconds and your are testing 1000000 values you will only have the following error precision per op: EDIT not homogen 16ms / (5*1000000) = 3.2 ns max error

EDIT:
Total time error : 0,016/5 = 0,32%

EDIT2 false again ;-)
per op error : 0,32%/nbop=0,32%/1000000= 0,00000032%

per op error : 0,32%



conclusion making a bench with enought values will give the same result with System.currentMillis than any other precision timer ;-), (because the arror of System.currentMillis does not grow with time)

Online Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #32 - Posted 2006-04-03 19:34:32 »

Yes, but the loop takes less than 70ms..

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DzzD
« Reply #33 - Posted 2006-04-03 19:43:55 »

ok, maybe it is too short even with good timer

@oravecz : thanks for developping this full bench with all differents methods

Offline DzzD
« Reply #34 - Posted 2006-04-03 20:01:55 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
   public static final int lookup(int val) 
   {
      if (val < 65536)
      {
         if (val < 256)
         {
            if(val<0)
               return -1;
            else
               return lookup[val];
         }
         else
            return lookup[val >> 8] << 8;
      }
      else
      {
         if (val < 16777216)
            return lookup[val >> 16] << 16;
         else
            return lookup[val >> 24] << 24;
      }
   }



review of the lookup method with a  better implementation of if/else statements , seems to give better results

Online Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #35 - Posted 2006-04-03 21:51:23 »

You can logicly remove a lot of 'else' statements from that code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public static final int lookup(int val) 
{
   if (val < 65536)
   {
      if (val < 256)
      {
         if(val<0)
            return -1;
         return lookup[val];
      }
      return lookup[val >> 8] << 8;
   }

   if (val < 16777216)
      return lookup[val >> 16] << 16;
   return lookup[val >> 24] << 24;
}


Very tempting to inline one if/else statement:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public static final int lookup(int val) 
{
   if (val < 65536)
   {
      if (val < 256)
         return (val<0) -1 ? lookup[val];
      return lookup[val >> 8] << 8;
   }

   if (val < 16777216)
      return lookup[val >> 16] << 16;
   return lookup[val >> 24] << 24;
}


But probably just as fast Wink

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline DzzD
« Reply #36 - Posted 2006-04-03 23:32:14 »

maybe but your code looks much cleaner,I am  really supid to put a else statement after a return :-)

Online Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #37 - Posted 2006-04-03 23:49:10 »

You can setup Eclipse to whine about it Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Pages: 1 [2]
  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.

BurntPizza (15 views)
2014-09-19 03:14:18

Dwinin (33 views)
2014-09-12 09:08:26

Norakomi (58 views)
2014-09-10 13:57:51

TehJavaDev (81 views)
2014-09-10 06:39:09

Tekkerue (40 views)
2014-09-09 02:24:56

mitcheeb (63 views)
2014-09-08 06:06:29

BurntPizza (46 views)
2014-09-07 01:13:42

Longarmx (33 views)
2014-09-07 01:12:14

Longarmx (38 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
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!