Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (578)
games submitted by our members
Games in WIP (499)
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  
  How fast is this?  (Read 1121 times)
0 Members and 1 Guest are viewing this topic.
Offline darkprophet

Senior Member




Go Go Gadget Arms


« Posted 2004-08-29 11: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 Coder


Medals: 1


http://t-machine.org


« Reply #1 - Posted 2004-08-29 12: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

Senior Member




Go Go Gadget Arms


« Reply #2 - Posted 2004-08-29 13: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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #3 - Posted 2004-08-29 14: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]
  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.

xsi3rr4x (29 views)
2014-04-15 18:08:23

BurntPizza (26 views)
2014-04-15 03:46:01

UprightPath (41 views)
2014-04-14 17:39:50

UprightPath (23 views)
2014-04-14 17:35:47

Porlus (40 views)
2014-04-14 15:48:38

tom_mai78101 (62 views)
2014-04-10 04:04:31

BurntPizza (122 views)
2014-04-08 23:06:04

tom_mai78101 (221 views)
2014-04-05 13:34:39

trollwarrior1 (188 views)
2014-04-04 12:06:45

CJLetsGame (197 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!