File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

100 Objects or 100 Calls

 
Mike Cole
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1868
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Here is what I have tried via code

 
Svend Rost
Ranch Hand
Posts: 904
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 245
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that there will be signicicant difference (the method will run 100 times in both cases).
 
Mike Cole
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rahul,

How are you getting these Execution Statistics ?

kundan
 
Rahul Mahindrakar
Ranch Hand
Posts: 1868
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Eclipse Test and Performance Tools
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic