Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  How fast is this?  (Read 883 times)
0 Members and 2 Guests are viewing this topic.
Offline darkprophet

JGO Neuromancer
****

Posts: 1171


Go Go Gadget Arms


« on: 2004-08-29 05:16:02 »

Hi all,
I have a forloop which loops through an ArrayList full of Entities.

What the for loop does is that it loops through the arraylist, obtains the Entity from the arraylist, then does a Entity.Hashmap.get(arg_name); if its true, then break.

So here it is in code:

1  
2  
3  
4  
5  
6  
7  
8  
public void getEntity(Spatial s) {
  String name = s.getName();
  for (int i = 0; i < entityArrayList.size(); i++) {
    Entity t = (Entity) entityArrayList.get(i);
    boolean hasName = t.containsSpatialName(name);
    if (hasName == true) break;
  }
}


Thats all it does. The only problem is that its in the same thread as the renderer (and I dont whish to change that). The ArrayList will by large have around at max 5000 Entities and I was wondering how fast this is and how large of an FPS hit would I have to bear.

Thx, DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline blahblahblahh

JGO Kernel
*****

Posts: 4575


http://t-machine.org


« Reply #1 on: 2004-08-29 06:35:14 »

Is it just me, or does that loop not do anything? Grin

Anyway, to answer your question: blindingly fast. Each operation will execute so fast you could blink and not see it happen Tongue.

Think about it: you're asking us to tell you how fast a particular loop runs on any unknown PC. Perhaps you could instead ask something quantified and important like "realistically, can I call hashCode() more than 1 million times every 1 ms on a modern PC?". Or something like "are there any performance problems with Arraylists with 5000 elements?" (to which the answer is YES!: be  a little careful about add's, and especially careful about indexOf's and remove's, which can be slow on mor than a few thousand elements)

OTOH, how many times do people have to say "optimize last" and "profile before optimizing"?

The question "this code is responsible for 65% of my runtime, which I can't explain at all" then that would be a very good question for people to help with. As it stands, it's a little hard to see how it could even show up at all in your profiler...

malloc will be first against the wall when the revolution comes...
Offline darkprophet

JGO Neuromancer
****

Posts: 1171


Go Go Gadget Arms


« Reply #2 on: 2004-08-29 07:59:32 »

the above code was an extract, and is not intended to be full code. Here is the full code:

1  
2  
3  
4  
5  
6  
7  
8  
public Entity getEntity(Spatial s) { 
  String name = s.getName();
  for (int i = 0; i < entityArrayList.size(); i++) {
    Entity t = (Entity) entityArrayList.get(i);
    boolean hasName = t.containsSpatialName(name);
    if (hasName == true) return t;
  }
}


The reason I ask is because I cannot create a test case where that is the case, this is pure speculation and the possibility of it happening is there. If this will be the downfall of the FPS, then perhaps I should design in a different matter.

As for the arraylist comment, there will be no IndexOf calls, perhaps some remove (but that is rare).

I dont have a profiler because I dont have the money to buy either OptimiseIT or JProbe.

I should have said, "Is this design with speed on mind sound?" rather than "is this fast"

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Games published by our own members! Go get 'em!
Offline blahblahblahh

JGO Kernel
*****

Posts: 4575


http://t-machine.org


« Reply #3 on: 2004-08-29 08:31:10 »

Then I think the most important answer for you is "I don't see anything stupid in there" (of course, I might have missed something Wink) - i.e. the actual code is not so spectacularly bad that it will fundamentally blow up (e.g. it's not iterating over the values of a hashtable, which is definitely a bad thing to do).

As to profiling, java comes with a free profiler. As Cas has explained lots of times in the past (which is why I dislike forums for programming - his comments are now buried somewhere in the distant past of his 3000 posts!), that free profiler is more than sufficient to do 90% of your profiling work. It doesn't draw fancy graphs, it doesn't produce colourful output, and it doesn't have a GUI. But...it does give you a very simple statement "these are the slowest parts of your program, this is how slow they are, and here are the line numbers" - which is all you need, really, unless you're doing exceptional stuff.

malloc will be first against the wall when the revolution comes...
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.068 seconds with 18 queries.