Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (602)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (650)
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 1142 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:

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

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.

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.

Jesse (16 views)
2015-07-29 04:35:27

Riven (37 views)
2015-07-27 16:38:00

Riven (19 views)
2015-07-27 15:35:20

Riven (22 views)
2015-07-27 12:26:13

Riven (12 views)
2015-07-27 12:23:39

BurntPizza (30 views)
2015-07-25 00:14:37

BurntPizza (42 views)
2015-07-24 22:06:39

BurntPizza (24 views)
2015-07-24 06:06:53

NoxInc (31 views)
2015-07-22 22:16:53

NoxInc (20 views)
2015-07-22 22:13:39
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!