Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
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 6753 times)
0 Members and 1 Guest are viewing this topic.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 438
Projects: 4


Hand over your head.


« Reply #30 - Posted 2006-04-03 20: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
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline DzzD
« Reply #31 - Posted 2006-04-03 21: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: 438
Projects: 4


Hand over your head.


« Reply #32 - Posted 2006-04-03 21: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
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DzzD
« Reply #33 - Posted 2006-04-03 21: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 22: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: 438
Projects: 4


Hand over your head.


« Reply #35 - Posted 2006-04-03 23: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
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline DzzD
« Reply #36 - Posted 2006-04-04 01: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: 438
Projects: 4


Hand over your head.


« Reply #37 - Posted 2006-04-04 01: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
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Pages: 1 [2]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (88 views)
2013-05-17 21:29:12

alaslipknot (96 views)
2013-05-16 21:24:48

gouessej (128 views)
2013-05-16 00:53:38

gouessej (123 views)
2013-05-16 00:17:58

theagentd (131 views)
2013-05-15 15:01:13

theagentd (119 views)
2013-05-15 15:00:54

StreetDoggy (161 views)
2013-05-14 15:56:26

kutucuk (184 views)
2013-05-12 17:10:36

kutucuk (185 views)
2013-05-12 15:36:09

UnluckyDevil (191 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.201 seconds with 21 queries.