wood burning stoves 2.0*
The moose likes Performance and the fly likes 100 Objects or 100 Calls Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "100 Objects or 100 Calls" Watch "100 Objects or 100 Calls" New topic
Author

100 Objects or 100 Calls

Mike Cole
Ranch Hand

Joined: Sep 25, 2006
Posts: 38
Hi all,

can someone explain me what is slower/faster or better/worse:
Haveing a list with 100 or more Objects and call a function from eachone
or or having the object once and call a function 100 Times.

(maybe you wonder how i came up with such a question?... well iam trying to find out how i should store a map like it is used by games)
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1849
Hi

Here is what I have tried via code

Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
Rahul, I think Michael assumed that the 100 objects already were created,
i.e. you shouldn't create the object before you call the method.

Michal, try to perform much like the one Rahul made.

for 1..100 do list[i].perform()

vs.

for 1..100 do obj.perform()

and compare the result.

From a performance point of view, creating a single object instead of
creating 100 object is obviously to be prefeered (memory) in the general case, however
im sure there are arguments for creating 100 objects instead of having
one single object performing 100 jobs.
[ September 27, 2006: Message edited by: Svend Rost ]
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245
I don't think that there will be signicicant difference (the method will run 100 times in both cases).
Mike Cole
Ranch Hand

Joined: Sep 25, 2006
Posts: 38
Hi all,
first, thank you for your efforts to help me!
Svend was right. The object creation itself is no problem... just
the function calls. But the hint about the moemory usage was good.
I didn�t think of that.... that can become a problem(sooner or later).
It looks like that i have to tryout all the possibilities.

Again thank you all!

cu

mk
kundan sinha
Greenhorn

Joined: Aug 01, 2005
Posts: 15
Hi Rahul,

How are you getting these Execution Statistics ?

kundan
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1849
Using Eclipse Test and Performance Tools
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 100 Objects or 100 Calls
 
Similar Threads
jsp and javascript
lacal variables availabiliy for GC
jsp
calling a servlet from javascript function??
Calling DLL function