• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to determine which is better?  RSS feed

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I figure out which is more efficient (memory/cpu)? I'd like a way to *prove* which option is more optimal. Do I keep executing a bean.getSomething() or assign it to a local variable? Note that bean.getSomething() just returns a property's value (no backend processing).

Thanks!

ron

Option 1:


OR

Option 2:
 
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If that code is executed often enough, the hotspot engine might well decide to inline the method call. So the performance characteristic will likely be near to indistinguishable. Worrying about it is likely to be nothing more than a waste of time...
 
Ron Hamilton
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response.

Perhaps it may seem like a waste of time. Certainly for a few method calls any performance degradation may not be noticed.

But what if that getter were being called 10 times? 100 times? X times?

I'm wondering if anyone knows of a way to prove this.

Thanks!

ron
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!