This content has been marked as final. Show 12 replies
the first case might be just a little better
how do you know you have a performance issue? clue: thanks to modern JVMs and their optimizing qualities, you almost certainly don't. never just assume something is going to be a performance bottleneck, do some testing to prove it
the first case might be just a little betterit almost certainly won't be, and in any case, if it were, we're talking about a few clock cycles - who's going to notice that, in an application that's accessing all sorts of other, slower resources? nobody, that's who
Which one is better approach? Which one will give meYou will get no noticeable performance improvement in one case vs the other.
All I can do is agree with the above posters. The extremely small time it will take to create the space needed for company and then assign a value to that is negligible.
All I can do is agree with the above posters. Theplus it's likely the compiler will inline the getCompany method anyway
extremely small time it will take to create the space
needed for company and then assign a value to that is
Guys, this is just a example. In my case, the called function will call another function. To execute all the line of code it will hardly taking a minute. But, i want to know the beeter approach. I think 2nd one is the better approach. What do u think?
Guys, this is just a example.So you don't actually have a performance issue at all?
I think 2nd one is the better approach.Do you have anything to back your claim?
What do u think?I think that you need empirical evidence to find out if X is 'better' than Y performance-wise.
Its my idea. Do you have any idea/ If yes, please share it.
Issues of performance? This may be related to latter replies in this thread:
Its my idea. Do you have any idea/ If yes, pleaseyou've been given a load of ideas above. the biggest idea, though, is that you shouldn't ever make any assumptions about what your performance bottlenecks will be. allow me to trot out one of my favourite articles once more :-)
regarding whether it is ok for you to embed a call to one method inside another a la
that's perfectly acceptable. if the methods are small enough - and they ought to be - the JVM will inline them anyway, that is, at runtime the two methods will be compiled into one larger, faster method. another consideration, though, is "what if the getOtherData() method returns null, or some other unsuitable value?". do you need special handling for that in the getCompanyName method, or in the method from which these calls are being made? that's the sort of question you need to ask yourself in these situations, not the "performance" red herring. in a system that paints a GUI, performs disk I/O or other resource-intensive work, trying to save a couple of clock cycles like above is a complete waste of time
and he thinks he's got performance problems...
Wonder what he'll do when he's got to deal with code that executes in milliseconds but spends minutes waiting for databases and network connections.
Will he still wonder whether he could shave off a few clock cycles by using obscure or unmaintainable code constructs?