Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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  
  Speed  (Read 1003 times)
0 Members and 1 Guest are viewing this topic.
Offline g666

Junior Devvie





« Posted 2006-03-05 15:08:24 »


Are larger arrays more expensive to acces? Becuase i find this:

   int npp = ((yi<<widthBits)+xi)<<2;
   int pixP1 = np[npp];
   int pixP2 = np[++npp];
   int pixP3 = np[++npp];
   int pixP4 = np[++npp];
      
to be ~0.75 the spped of this and the above is doing less

   int pixP1 = getTexel(xi, yi);
   int pixP2 = getTexel(xi+1, yi);
   int pixP3 = getTexel(xi, yi+1);
   int pixP4 = getTexel(xi+1, yi+1);

the method used above:
      
   public final int getTexel(int x, int y){
      return imgData[((y & heightMask) << widthBits) + (x & widthMask)];
   }

desperately seeking sanity
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #1 - Posted 2006-03-05 15:28:24 »

Try this version for me, and tell me if you're still seeing a speed difference:

1  
2  
3  
4  
5  
6  
7  
8  
   int npp1 = ((yi<<widthBits)+xi)<<2;
   int npp2 = ((yi<<widthBits)+(xi+1))<<2;
   int npp3 = ((yi<<widthBits)+(xi+2))<<2;
   int npp4 = ((yi<<widthBits)+(xi+3))<<2;
   int pixP1 = np[npp1];
   int pixP2 = np[npp2];
   int pixP3 = np[npp3];
   int pixP4 = np[npp4];


I have a feeling that Hotspot is optimizing the starch out of your routine. As a result, the latter version is completely inlined. Once inlined, it then shows up as faster due to the CPU's ability to execute out-of-order instructions. As long as you rely on a the same variable for every line, the CPU is required to execute the lines one after another.

Java Game Console Project
Last Journal Entry: 12/17/04
Offline Jeff

JGO Coder




Got any cats?


« Reply #2 - Posted 2006-03-06 02:38:17 »

Uh huh.

As usual, a microbenchmark fails to measure what it thinks it is.

Microbenchmarking a VM with a JIT and gettign meaningful results is very hard unless you really understand the deatisl of how the VM does its compilation.

Otherwise, the best benchmarks are real code performing complete functions over a reasonably long epriod of time.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline g666

Junior Devvie





« Reply #3 - Posted 2006-03-06 20:53:42 »

What jbanes suggested does yeild an improvement. Thank you.

PS. this isnt a benchmark, it is real code being called in a real function millions of times a second. XD

desperately seeking sanity
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #4 - Posted 2006-03-06 21:26:48 »

What jbanes suggested does yeild an improvement.

That's pretty much what I figured. In a modern, superscalar, out-of-order CPU, the more instructions you can untangle, the better the performance. It's quite possible that each line you access is executing in parallel with the other lines. For the absolute fastest code, try this version:

1  
2  
3  
4  
5  
int npp = ((yi<<widthBits)+xi)<<2;
   int pixP1 = np[npp];
   int pixP2 = np[npp+1];
   int pixP3 = np[npp+2];
   int pixP4 = np[npp+3];


There are no guarantees, but that might eliminate some of the extra processing you were trying to get rid of.

Quote
Thank you.

You're welcome. Smiley

Java Game Console Project
Last Journal Entry: 12/17/04
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.

toopeicgaming1999 (71 views)
2014-11-26 15:22:04

toopeicgaming1999 (60 views)
2014-11-26 15:20:36

toopeicgaming1999 (14 views)
2014-11-26 15:20:08

SHC (27 views)
2014-11-25 12:00:59

SHC (25 views)
2014-11-25 11:53:45

Norakomi (31 views)
2014-11-25 11:26:43

Gibbo3771 (25 views)
2014-11-24 19:59:16

trollwarrior1 (38 views)
2014-11-22 12:13:56

xFryIx (77 views)
2014-11-13 12:34:49

digdugdiggy (55 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!