• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

100 Objects or 100 Calls

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Here is what I have tried via code

 
Ranch Hand
Posts: 904
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rahul,

How are you getting these Execution Statistics ?

kundan
 
Rahul Mahindrakar
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using Eclipse Test and Performance Tools
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic